计算f(x1,x2)=x0^2+x1^2-x0*x1-10*x0-4*x1+60#includestdio.h#includestdlib.h#includemath.hdoubleobjf(doublex[]){doubleff;ff=x[0]*x[0]+x[1]*x[1]-x[0]*x[1]-10*x[0]-4*x[1]+60;return(ff);}voidjtf(doublex0[],doubleh0,doubles[],intn,doublea[],doubleb[]){inti;double*x[3],h,f1,f2,f3;for(i=0;i3;i++)x[i]=(double*)malloc(n*sizeof(double));h=h0;for(i=0;in;i++)*(x[0]+i)=x0[i];f1=objf(x[0]);for(i=0;in;i++)*(x[1]+i)=*(x[0]+i)+h*s[i];f2=objf(x[1]);if(f2=f1){h=-h0;for(i=0;in;i++)*(x[2]+i)=*(x[0]+i);f3=f1;for(i=0;in;i++){*(x[0]+i)=*(x[1]+i);*(x[1]+i)=*(x[2]+i);}f1=f2;f2=f3;}for(;;){h=2*h;for(i=0;in;i++)*(x[2]+i)=*(x[1]+i)+h*s[i];f3=objf(x[2]);if(f2f3)break;else{for(i=0;in;i++){*(x[0]+i)=*(x[1]+i);*(x[1]+i)=*(x[2]+i);}f1=f2;f2=f3;}}if(h0)for(i=0;in;i++){a[i]=*(x[2]+i);b[i]=*(x[0]+i);}elsefor(i=0;in;i++){a[i]=*(x[0]+i);b[i]=*(x[2]+i);}for(i=0;i3;i++)free(x[i]);}doublegold(doublea[],doubleb[],doubleeps,intn,doublexx[]){inti;doublef1,f2,*x[2],ff,q,w;for(i=0;i2;i++)x[i]=(double*)malloc(n*sizeof(double));for(i=0;in;i++){*(x[0]+i)=a[i]+0.618*(b[i]-a[i]);*(x[1]+i)=a[i]+0.382*(b[i]-a[i]);}f1=objf(x[0]);f2=objf(x[1]);do{if(f1f2){for(i=0;in;i++){b[i]=*(x[0]+i);*(x[0]+i)=*(x[1]+i);}f1=f2;for(i=0;in;i++)*(x[1]+i)=a[i]+0.382*(b[i]-a[i]);f2=objf(x[1]);}else{for(i=0;in;i++){a[i]=*(x[1]+i);*(x[1]+i)=*(x[0]+i);}f2=f1;for(i=0;in;i++)*(x[0]+i)=a[i]+0.618*(b[i]-a[i]);f1=objf(x[0]);}q=0;for(i=0;in;i++)q=q+(b[i]-a[i])*(b[i]-a[i]);w=sqrt(q);}while(weps);for(i=0;in;i++)xx[i]=0.5*(a[i]+b[i]);ff=objf(xx);for(i=0;i2;i++)free(x[i]);return(ff);}doubleoneoptim(doublex0[],doubles[],doubleh0,doubleepsg,intn,doublex[]){double*a,*b,ff;a=(double*)malloc(n*sizeof(double));b=(double*)malloc(n*sizeof(double));jtf(x0,h0,s,n,a,b);ff=gold(a,b,epsg,n,x);free(a);free(b);return(ff);}doublepowell(doublep[],doubleh0,doubleeps,doubleepsg,intn,doublex[]){inti,j,m;double*xx[4],*ss,*s;doublef,f0,f1,f2,f3,fx,dlt,df,sdx,q,d;ss=(double*)malloc(n*(n+1)*sizeof(double));s=(double*)malloc(n*sizeof(double));for(i=0;in;i++){for(j=0;j=n;j++)*(ss+i*(n+1)+j)=0;*(ss+i*(n+1)+i)=1;}for(i=0;i4;i++)xx[i]=(double*)malloc(n*sizeof(double));for(i=0;in;i++)*(xx[0]+i)=p[i];for(;;){for(i=0;in;i++){*(xx[1]+i)=*(xx[0]+i);x[i]=*(xx[1]+i);}f0=f1=objf(x);dlt=-1;for(j=0;jn;j++){for(i=0;in;i++){*(xx[0]+i)=x[i];*(s+i)=*(ss+i*(n+1)+j);}f=oneoptim(xx[0],s,h0,epsg,n,x);df=f0-f;if(dfdlt){dlt=df;m=j;}}sdx=0;for(i=0;in;i++)sdx=sdx+fabs(x[i]-(*(xx[1]+i)));if(sdxeps){free(ss);free(s);for(i=0;i4;i++)free(xx[i]);return(f);}for(i=0;in;i++)*(xx[2]+i)=x[i];f2=f;for(i=0;in;i++){*(xx[3]+i)=2*(*(xx[2]+i)-(*(xx[1]+i)));x[i]=*(xx[3]+i);}fx=objf(x);f3=fx;q=(f1-2*f2+f3)*(f1-f2-dlt)*(f1-f2-dlt);d=0.5*dlt*(f1-f3)*(f1-f3);if((f3f1)||(qd)){if(f2=f3)for(i=0;in;i++)*(xx[0]+i)=*(xx[2]+i);elsefor(i=0;in;i++)*(xx[0]+i)=*(xx[3]+i);}else{for(i=0;in;i++){*(ss+(i+1)*(n+1))=x[i]-(*(xx[1]+i));*(s+i)=*(ss+(i+1)*(n+1));}f=oneoptim(xx[0],s,h0,epsg,n,x);for(i=0;in;i++)*(xx[0]+i)=x[i];for(j=m+1;j=n;j++)for(i=0;in;i++)*(ss+i*(n+1)+j-1)=*(ss+i*(n+1)+j);}}}voidmain(){doublep[]={1,2};doubleff,x[2];ff=powell(p,0.3,0.001,0.0001,2,x);printf(x[0]=%f,x[1]=%f,ff=%f\n,x[0],x[1],ff);getchar();}#includestdio.h#includemath.hvoidmain(){floatx1[20],x2[20],y[20],a[20];floatX1,X2,ymin,e;intk;printf(inputx1[0]x2[0]e\n);scanf(%f,%f,%f,&x1[0],&x2[0],&e);printf(x1\t\tx2\t\ty\t\ta\n);k=0;do{a[k]=(625*x2[k]*x2[k]+x1[k]*x1[k])/(2*x1[k]*x1[k]+625*50*x2[k]*x2[k]);x1[k+1]=x1[k]-a[k]*2*x1[k];x2[k+1]=x2[k]-a[k]*50*x2[k];y[k+1]=x1[k+1]*x1[k+1]+25*x2[k+1]*x2[k+1];printf(\n%f\t%f\t%f\t%f\t,x1[k+1],x2[k+1],y[k+1],a[k]);k=k+1;}while((x1[k]-x1[k-1])e);X1=x1[k];X2=x2[k];ymin=X1*X1+25*X2*X2;printf(\n%f\t%f\t%f,X1,X2,ymin);}3、抓屏结果黄金分割法1、数学模型Y=(x-2)(x-3)2、方法简介黄金分割法适用于[a,b]区间的任何单谷函数极小值问题。在搜索区间a-b内插入两点a1和a2,将其分为三段,并且计算其函数值。比较大小,删去其中一段,使得搜索区间减小,如此迭代下去。3、程序代码#includestdio.h#includemath.hdoublef(doublex){return(x-2)*(x-3);}voidmain(void){doublea1,y1,a2,y2,a,b,k,e;a=0;b=10;e=0.001;k=0.618;a1=b-k*(b-a);y1=f(a1);a2=a+k*(b-a);y2=f(a2);printf(a\ta1\t\ta2\tb\t\ty1\ty2\n);while(fabs(b-a)e){if(y1=y2){a=a1;a1=a2;y1=y2;a2=a+k*(b-a);y2=f(a2);}else{b=a2;a2=a1;y2=y1;a1=b-k*(b-a);y1=f(a1);}printf(%f%f%f%f%f%f\n,a,a1,a2,b,y1,y2);}printf(x*=%f\n,(a1+a2)/2);printf(y*=%f\n,y1);}4、抓屏结果1234567890ABCDEFGHIJKLMNabcdefghijklmn!@#$%^&&*()_+.一三五七九贰肆陆扒拾,。青玉案元夕东风夜放花千树更吹落星如雨宝马雕车香满路凤箫声动玉壶光转一夜鱼龙舞蛾儿雪柳黄金缕笑语盈盈暗香去众里寻他千百度暮然回首那人却在灯火阑珊处你可能喜欢优化设计进退法鲍威尔法优化设计黄金分割法优化设计Matlab...机械优化设计实验报告机械优化设计考试Powell法惩罚函数法机械优化设计进退法程序2页免费机械优化设计上机实验指导书-进退法4页免费优化设计进退法程序2页2财富值机械优化设计-进退法1页免费机械优化设计进退法程序(郑大)暂无评价2页1财富值更多与“优化设计进退法”相关的文档©2013Baidu使用百度前必读|文库协议分享到:QQ空间新浪微博微信