请问谁知道Remes的matlab程序代码
谢谢回复:(brianlei)请问谁知道Remes的matlab程序代码
C常用算法程序集里有C语言的remes算法,改写一下就行了 <P>谁能贴一下c程序,我试着翻译一下</P>回复:(brianlei)请问谁知道Remes的matlab程序代码
<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;<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);<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,g,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=(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; xx=g;<BR> for (i=j; i<=n-1; i++)<BR> { t=p; x0=g;<BR> p=(s-t)/(x-x);<BR> g=(xx-x0)/(x-x);<BR> k=n-i+j; s=t; xx=x0;<BR> }<BR> }<BR> u=-p/g;<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; s=p;<BR> for (i=m-j; i<=n; i++)<BR> { t=p; p=s-h*t;<BR> s=t; k=i;<BR> }<BR> }<BR> p=fabs(u); u=p;<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;<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;<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) j=k;<BR> else i=k;<BR> }<BR> if (xx<x)<BR> { s=hremzf(x); t=p;<BR> for (k=n-2; k>=0; k--)<BR> t=t*x+p;<BR> s=s-t;<BR> if (s*yy>0.0) x=xx;<BR> else<BR> { for (k=n-1; k>=0; k--)<BR> x=x;<BR> x=xx;<BR> }<BR> }<BR> else<BR> { if (xx>x)<BR> { s=hremzf(x); t=p;<BR> for (k=n-2; k>=0; k--)<BR> t=t*x+p;<BR> s=s-t;<BR> if (s*yy>0.0) x=xx;<BR> else<BR> { for (k=0; k<=n-1; k++)<BR> x=x;<BR> x=xx;<BR> }<BR> }<BR> else<BR> { i=i-1; j=j-1;<BR> s=hremzf(x); t=p;<BR> for (k=n-2; k>=0; k--)<BR> t=t*x+p;<BR> s=s-t;<BR> if (s*yy>0.0) x=xx;<BR> else x=xx;<BR> }<BR> }<BR> }<BR>}</P>
页:
[1]