<P><FONT color=#ff0000><STRONG>主程序:</STRONG></FONT><BR><BR> #include "math.h"<BR> #include "stdio.h"<BR> #include "hremz.c"<BR> main()<BR> { int i;<BR> double a,b,eps,p[5];<BR> a=-1.0; b=1.0; eps=1.0e-10;<BR> hremz(a,b,p,4,eps);<BR> printf("\n");<BR> for (i=0; i<=3; i++)<BR> printf("p(%2d)=%e\n",i,p);<BR> printf("\n");<BR> printf("MAX(p-f)=%e\n",p[4]);<BR> printf("\n");<BR> }</P>
<P> double hremzf(x)<BR> double x;<BR> { double y;<BR> y=exp(x);<BR> return(y);<BR> }<BR><BR><BR><BR><FONT color=#ff0000><STRONG>remes程序:</STRONG></FONT><BR><BR> #include "math.h"<BR> void hremz(a,b,p,n,eps)<BR> int n;<BR> double a,b,eps,p[];<BR> { extern double hremzf();<BR> int i,j,k,m;<BR> double x[21],g[21],d,t,u,s,xx,x0,h,yy;<BR> if (n>20) n=20;<BR> m=n+1; d=1.0e+35;<BR> for (k=0; k<=n; k++)<BR> { t=cos((n-k)*3.1415926/(1.0*n));<BR> x[k]=(b+a+(b-a)*t)/2.0;<BR> }<BR> while (1==1)<BR> { u=1.0;<BR> for (i=0; i<=m-1; i++)<BR> { p=hremzf(x);<BR> g=-u; u=-u;<BR> }<BR> for (j=0; j<=n-1; j++)<BR> { k=m; s=p[k-1]; xx=g[k-1];<BR> for (i=j; i<=n-1; i++)<BR> { t=p[n-i+j-1]; x0=g[n-i+j-1];<BR> p[k-1]=(s-t)/(x[k-1]-x[m-i-2]);<BR> g[k-1]=(xx-x0)/(x[k-1]-x[m-i-2]);<BR> k=n-i+j; s=t; xx=x0;<BR> }<BR> }<BR> u=-p[m-1]/g[m-1];<BR> for (i=0; i<=m-1; i++)<BR> p=p+g*u;<BR> for (j=1; j<=n-1; j++)<BR> { k=n-j; h=x[k-1]; s=p[k-1];<BR> for (i=m-j; i<=n; i++)<BR> { t=p[i-1]; p[k-1]=s-h*t;<BR> s=t; k=i;<BR> }<BR> }<BR> p[m-1]=fabs(u); u=p[m-1];<BR> if (fabs(u-d)<=eps) return;<BR> d=u; h=0.1*(b-a)/(1.0*n);<BR> xx=a; x0=a;<BR> while (x0<=b)<BR> { s=hremzf(x0); t=p[n-1];<BR> for (i=n-2; i>=0; i--)<BR> t=t*x0+p;<BR> s=fabs(s-t);<BR> if (s>u) { u=s; xx=x0;}<BR> x0=x0+h;<BR> }<BR> s=hremzf(xx); t=p[n-1];<BR> for (i=n-2; i>=0; i--)<BR> t=t*xx+p;<BR> yy=s-t; i=1; j=n+1;<BR> while ((j-i)!=1)<BR> { k=(i+j)/2;<BR> if (xx<x[k-1]) j=k;<BR> else i=k;<BR> }<BR> if (xx<x[0])<BR> { s=hremzf(x[0]); t=p[n-1];<BR> for (k=n-2; k>=0; k--)<BR> t=t*x[0]+p[k];<BR> s=s-t;<BR> if (s*yy>0.0) x[0]=xx;<BR> else<BR> { for (k=n-1; k>=0; k--)<BR> x[k+1]=x[k];<BR> x[0]=xx;<BR> }<BR> }<BR> else<BR> { if (xx>x[n])<BR> { s=hremzf(x[n]); t=p[n-1];<BR> for (k=n-2; k>=0; k--)<BR> t=t*x[n]+p[k];<BR> s=s-t;<BR> if (s*yy>0.0) x[n]=xx;<BR> else<BR> { for (k=0; k<=n-1; k++)<BR> x[k]=x[k+1];<BR> x[n]=xx;<BR> }<BR> }<BR> else<BR> { i=i-1; j=j-1;<BR> s=hremzf(x); t=p[n-1];<BR> for (k=n-2; k>=0; k--)<BR> t=t*x+p[k];<BR> s=s-t;<BR> if (s*yy>0.0) x=xx;<BR> else x[j]=xx;<BR> }<BR> }<BR> }<BR> }</P>
|