ÏÂÔؿɱà¼
result =t; } } } int main() {
double a = 0.0; double b = 3.0; double x= newton(a,b);
cout<<\Çó½âµÄ½á¹ûÊÇ x = \ cout<<\´Ëʱf(x) = \ return 0; }
¸½Â¼4
#include
return (t*t+2*t); }
void Goldensection(double(*pfun)(double t)) {
int maxflag=1000,k=1;
double a=-3,b=5,err=0.001,t,t1,t2; do {
t1=a+0.618*(b-a); t2=b-0.618*(b-a); if(t1=t2){a=t2;b=t1;} else {if(t1 }while(fabs(a-b)>err&&k cout< t=(a+b)/2; cout< cout<<\µü´ú½á¹û£º½üËƸùΪroot=\º¯ÊýÖµ½üËÆΪ£ºf(root)=\} int main() { .רҵ.ÕûÀí. ÏÂÔؿɱ༠Goldensection(fun); return 0; } ¸½Â¼5 #include return (8*x*x*x-2*x*x-7*x+3); } double max(double a,double b) { if(a>b)return a; else return b; } double min(double a,double b) { if(a>b)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)*f un(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<<\µü´ú½á¹û£º\.רҵ.ÕûÀí. ÏÂÔؿɱ༠cout<<\½üËƸù:\ cout<<\º¯ÊýÖµ½üËÆΪ:\} int main() { Parainterpolation(fun); return 0; } ¸½Â¼6 #include double lamda(double x[2],double p[2],double a[2]) { double lam1,lam2; lam1=(pow(a[0],3)*x[0]*x[0]+pow(a[1],3)*x[1]*x[1]); lam2=-(pow(a[0]*x[0],2)+pow(a[1]*x[1],2)); double s; s=-lam2/(2*lam1); return s; } void main() { cout<<\×îËÙϽµ·¨Çó½â×îÓŽâ³ÌÐòÔËÐнá¹û\ cout< double lamd,x[3],a[6]; double p[2],g[2],e,y,m,n; int i=0; cout<<\ÇëÊäÈ뾫¶Èe\ cout<<\ÇëÊäÈë³õʼµãx[0],x[1]µÄÖµ£º\\n\ cin>>m; cin>>n; x[0]=m; x[1]=n; cout<<\º¯ÊýͨʽΪf(x)=a[0]x1*x1+a[1]x2*x2+a[2]x1*x2+a[3]x1+a[4]x2+a[5]\ cout<<\ÇëÒÀ´ÎÊäÈ뺯ÊýµÄϵÊý£ºa[0]¡¢a[1]¡¢a[2]¡¢a[3]¡¢a[4]¡¢a[5]:\ for(i=0;i<6;i++) cin>>a[i]; p[0]=(2*a[0]*x[0]+a[2]*x[1]+a[3]); p[1]=(2*a[1]*x[1]+a[2]*x[0]+a[4]); g[0]=-p[0]; g[1]=-p[1]; i=0; cout< ÏÂÔؿɱ༠g[0]=-p[0]; g[1]=-p[1]; i++; cout<<\ cout<<\µÚ\´Îµü´ú½á¹û£º\ cout<<\µÄģΪ£º\ cout<<\µÄÖµ\ cout<<\ cout< y=(a[0]*x[0]*x[0]+a[1]*x[0]*x[1]+a[2]*x[0]*x[1]+a[3]*x[0]+a[4]*x[1]+a[5]); cout<<\´ËʱÂú×㾫¶ÈÒªÇóµÄpµÄģΪ:\ cout< cout<<\Âú×㾫¶ÈµÄ×îÓŽüËƽá¹ûx[1],x[2]·Ö±ðΪ£º\ cout<<\ cout<<\ cout<<\Âú×ã½ø¶ÈÒªÇóËùµÃµÄ×îÓÅֵΪ£º\cout<<\ } ¸½Â¼7 #include #include\¾ØÕóµÄÓйØÔËËã int const n1=2; double f(double *x);//Ä¿±êº¯Êý; void g(double *x,double *y);//Ä¿±êº¯ÊýµÄÌݶÈ; void main() { int i; double x0[n1],x1[n1],g0[n1],g1[n1],H[n1][n1],h[n1][n1],p[n1],f0,f1,temp,e; x0[0]=0;x0[1]=0;e=0.01;H[0][0]=2;H[0][1]=-1;H[1][0]=-1;H[1][1]=2; f0=f(x0); g(x0,g0); matrix_inv(H,h); matrix_mul(h,g0,p); //matrix_minus(x0,p,x1); for(i=0;i x1[i]=x0[i]-p[i]; g(x1,g1); f1=f(x1); temp=g1[0]*g1[0]+g1[1]*g1[1]; while(temp>e) {