资源描述:
《机械优化设计c语言程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、计算f(x1,x2)=x0^2+x1^2-x0*x1-10*x0-4*x1+60#include"stdio.h"#include"stdlib.h"#include"math.h"doubleobjf(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;fo
2、r(i=0;i<3;i++)x[i]=(double*)malloc(n*sizeof(double));h=h0;for(i=0;i=f1){h=-h0;for(i=0;i3、1=f2;f2=f3;}for(;;){h=2*h;for(i=0;i4、);}for(i=0;i<3;i++)free(x[i]);}doublegold(doublea[],doubleb[],doubleeps,intn,doublexx[]){inti;doublef1,f2,*x[2],ff,q,w;for(i=0;i<2;i++)x[i]=(double*)malloc(n*sizeof(double));for(i=0;i5、(x[1]);do{if(f1>f2){for(i=0;i6、i=0;ieps);for(i=0;i7、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)
8、);s=(double*)malloc(n*sizeof(double));for(i=0;i