线性插值公式

版权声明:请勿商业化使用 https://blog.csdn.net/qq_40991687/article/details/89524881

问题描述:
已知某多叶调节风阀,当叶片数n=3时,叶片与气流方向成x度,某局部阻力系数y值
x 0 15 20 45 60 75
y 0.25 0.7 2.8 6.5 20 60
当x=30时,求y的线性插值
问题分析:
线性插值公式:
线性插值公式
其余代码里一切皆有

线性插值问题

输入

20 2.8 45 6.5
30
#include<cstdio>
#include<cmath>
void show(double a[]) {
 double m;
 scanf("%lf",&m);//待测值
 printf("线性插值公式:y = (x-%.2lf)/%.2lf*%.2lf + (x-%.2lf)/%.2lf*%.2lf\n",a[2],a[0]-a[2],a[1],a[0],a[2]-a[0],a[3]);//将数组a中数据代入线性插值公式
 printf("结果:%.2lf\n",1.*(m-a[2])/(a[0]-a[2])*a[1]+(m-a[0])/(a[2]-a[0])*a[3]);
}
int main() {
 double a[4];
 for(int i=0; i<4; ++i)
  scanf("%lf",a+i);//分别输入X0,Y0,X1,Y1
 show(a);
 return 0;
}

运行结果:

线 性 插 值 公 式 : y = (x-45.00)/-25.00*2.80 + (x-20.00)/25.00*6.50
结 果 : 4.28

猜你喜欢

转载自blog.csdn.net/qq_40991687/article/details/89524881