抛物线插值法.docVIP

  • 117
  • 0
  • 约小于1千字
  • 约 2页
  • 2021-11-23 发布于河北
  • 举报
抛物线插值法 #includeiostream #includemath.h using namespace std; double fun(double x) { return (8*x*x*x-2*x*x-7*x+3); } double max(double a,double b) { if(ab)return a; else return b; } double min(double a,double b) { if(ab)return b; else return a; } void Parainterpolation(double(*pfun)(double x)) { double a=0,b=2,err=0.001,x=0,x0=1,f,f0; do { x=((x0*x0-b*b)*fun(a)+(b*b-a*a)*fun(x0)+(a*a-x0*x0)*fun(b))/(2*((x0-b)*fun(a)+(b-a)*fun(x0)+(a-x0)*fun(b))); f0=fun(x0); f=fun(x); if(f=f0){a=min(x,x0);b=max(x,x0);x0=(a+b)/2;} else { if((fun(x)-f0)*(x-x0)0) { b=max(x,x0);x0=min(x,x0); } else { a=min(x,x0);x0=max(x,x0); } } }while(fabs(x-x0)err); x=(x+x0)/2; cout 迭代结果:近似根为root=xendl; cout 函数值近似为:f(root)=fun(x)endl; } int main() { Parainterpolation(fun); return 0; }

文档评论(0)

1亿VIP精品文档

相关文档