《机械优化设计随机法程序设计(共3页).doc》由会员分享,可在线阅读,更多相关《机械优化设计随机法程序设计(共3页).doc(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上#include stdio.h#include stdlib.h#include math.hdouble objf(double x)double ff;ff=pow(x0-4),2)+pow(x1-5),2);return(ff);/*约束条件子程序*/double strain(double x)int i;double g3;g0=x0-1;g1=x1-1;g2=8-x0-x1;for (i=0;i3;i+)if(g0)return(0);return(1);double rn(double *r)int m;double s,u,v,p;s=65536.0
2、;u=2053.0;v=13849.0;*r=u*(*r)+v;m=(int)(*r/s);*r=*r-m*s;p=*r/s;return(p);double randopti(double x,double xl,double xh,double a0,double eps,int n,int nmax)int i,iw,k,jj=0;double *x0,*s,a,f0,f,rr=0,ss;x0=(double *)malloc(n*sizeof(double);s=(double *)malloc(n*sizeof(double);dofor(i=0;i2000)printf(找不到初始
3、可行点!);return(-1);while(iw!=1);a=a0;f0=objf(x0);for(;)k=1;jj=0;L1:ss=0;for(i=0;in;i+)*(s+i)=rn(&rr);for(i=0;in;i+)ss+=*(s+i)*(*(s+i);for(i=0;in;i+)*(s+i)=*(s+i)/sqrt(ss);*(x+i)=*(x0+i)+a*(*(s+i);doiw=strain(x);if(iw=1)f=objf(x);if(ff0)for(i=0;inmax)if(aeps)a=a *0.5;elsefree(x0);free (s);return(objf(x);elsegoto L1;void main()double a=0,0;double b=8,9;double c,x2;c=randopti(x,a,b,1,0.00001,2,50);printf(输出最优点及其目标函数值:n);printf(x0=%f,x1=%f,ff=%f n,x0,x1,c);getchar();专心-专注-专业