functionecczsymsx;%定义f=25.666667*(5-4*x+x^2)+38.5*(1+x^2);%目标函数a1=0.5;a2=1.5;a3=1;%插值区间k=0;while(abs(a3-a1)1.0e-7)%精度f1=subs(f,x,a1);f2=subs(f,x,a2);f3=subs(f,x,a3);C1=(f3-f1)/(a3-a1);C2=((f2-f1)/(a2-a1)-C1)/(a2-a3);ap=0.5*(a1+a3-C1/C2);fp=subs(f,x,ap);ifapa2;iff2=fpa1=a2;f1=f2;a2=ap;f2=fp;elsea3=ap;f3=fp;endelseiff2=fp;a3=a2;f3=f2;a2=ap;f2=fp;elsea1=ap;f1=fp;endendk=k+1a=apff=subs(f,x,ap)end