您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 汽车理论 > 二次插值法C语言程序
二次插值法C语言程序#includestdio.h#includemath.h#includeconio.hvoidmain(){float*area(floata1,floatp,floata[3]);floatf(floatx);floatar,fr;floata1=10,p=0.01,e=0.000001;floatpa[3];area(a1,p,pa);a1=pa[0];floata2=pa[1];floata3=pa[2];floatf1=f(a1);floatf2=f(a2);floatf3=f(a3);do{ar=((a3*a3-a2*a2)*f1+(a1*a1-a3*a3)*f2+(a2*a2-a1*a1)*f3);ar=ar/2/((a3-a2)*f1+(a1-a3)*f2+(a2-a1)*f3);fr=f(ar);if(ara2){if(frf2){a3=ar;f3=fr;}elseif(frf2){a1=a2;f1=f2;a2=ar;f2=fr;}else{a3=ar;a1=a2;a2=(a1+a3)/2;f1=f2;f3=fr;f2=f(a2);}}elseif(ara2){if(frf2){a1=ar;f1=fr;}elseif(frf2){a3=a2;f3=f2;a2=ar;f2=fr;}else{a1=ar;a3=a2;a2=(a1+a3)/2;f1=fr;f3=f2;f2=f(a2);}}if(fabs(a1-a3)=e)break;}while(1);if(f2fr){ar=a2;fr=f2;}printf(\nx=%f\nf(x*)=%f,ar,fr);}float*area(floata1,floatp,floata[3]){floatf(floatx);floata2,f2,a3,f3,temp;floatacc=0.00001;floatf1=f(a1);floatstorep=p;while(1){a2=a1+p;f2=f(a2);if(f2=f1){if(fabs(f2-f1)acc)p=p/2;elsep=-p;}elsebreak;}while(1){a3=a2+p;f3=f(a3);if(f2=f3)break;p=2*p;a1=a2;f1=f2;a2=a3;f2=f3;}if(a1a3){temp=a1;a1=a3;a3=temp;}a[0]=a1;a[1]=a2;a[2]=a3;returna;}floatf(floatx){floaty=pow(fabs(x-1),1.5)+pow(fabs(x-1),2.7);returny;}
本文标题:二次插值法C语言程序
链接地址:https://www.777doc.com/doc-3768482 .html