如何用分段线性插值求某个函数值?已知:x=0.0,0.1,0.195,0.3,0.401,0.5时,f(x)分别=0.39894,0.39695,0.39142,0.38138,0.36812,0.35206 怎么编一个C程序,求得f(x)的分段线性插值结果.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/15 14:45:39
如何用分段线性插值求某个函数值?已知:x=0.0,0.1,0.195,0.3,0.401,0.5时,f(x)分别=0.39894,0.39695,0.39142,0.38138,0.36812,0.35206 怎么编一个C程序,求得f(x)的分段线性插值结果.
如何用分段线性插值求某个函数值?
已知:
x=0.0,0.1,0.195,0.3,0.401,0.5时,
f(x)分别=0.39894,0.39695,0.39142,0.38138,0.36812,0.35206
怎么编一个C程序,求得f(x)的分段线性插值结果.
如何用分段线性插值求某个函数值?已知:x=0.0,0.1,0.195,0.3,0.401,0.5时,f(x)分别=0.39894,0.39695,0.39142,0.38138,0.36812,0.35206 怎么编一个C程序,求得f(x)的分段线性插值结果.
#include
void main()
{
double x[6] = {0.0,0.1,0.195,0.3,0.401,0.5};
double f[6] = {0.39894,0.39695,0.39142,0.38138,0.36812,0.35206};
double input;
double output;
scanf("%lf",&input);
int i;
for (i = 0; i < 5; i++)
{
if (x[i] = input)
{
output = (f[i] * x[i] + f[i + 1] * x[i + 1]) / (x[i] + x[i + 1]);
break;
}
}
printf("%lf\n",output);
}