资源描述:
《约束坐标轮换法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#includedoubleminfun(doublex1,doublex2){doublef;f=x1*x1+2*x2*x2-4*x1-8*x2+15;returnf;}doubleg1(doublex1,doublex2){doublef;f=9-x1*x1-x2*x2;returnf;}doubleg2(doublex1,doublex2){doublef;f=x1+0*x2;returnf;}doubleg3(doublex1,doublex2){doublef;f=0*x1+x2;returnf;}intmain(){doublex0[2
2、],h0,e,x1[2],x2[2],a0;doublee1[2]={1,0},e2[2]={0,1};doublefx0,fx1,fx2,fx11[100],fx22[100];inti,j,k;h0=0.5;e=0.0001;printf("请输入初始点x0:");scanf("%lf%lf",&x0[0],&x0[1]);printf("%lf%lf",x0[0],x0[1]);if(g1(x0[0],x0[1])>=0&&g2(x0[0],x0[1])>=0&&g3(x0[0],x0[1])>=0){fx0=minfun(x0[0],x0[1]);pri
3、ntf("fx0=%lf",fx0);}else{printf("请重新输入初始点x0:");scanf("%lf%lf",&x0[0],&x0[1]);}//实现初始点的判断;for(k=0;;k++){for(i=0;i<2;i++)x1[i]=x0[i]+h0*e1[i];printf("%lf%lf",x1[0],x1[1]);if(g1(x1[0],x1[1])>=0&&g2(x1[0],x1[1])>=0&&g3(x1[0],x1[1])>=0){fx1=minfun(x1[0],x1[1]);printf("fx1=%lf",fx1);if
4、(fx1=0&&g2(x1[0],x1[1])>=0&&g3(x1[0],x1[1])>=0){fx11[j]=minfun(x1[0],x1[1]);printf("fx1=%lf",fx11[j]);if(fx11[j]5、0]=x1[0];x0[1]=x1[1];a0=2*a0;j++;}//实现X方向的多次搜索;elsebreak;}elsebreak;}for(i=0;i<2;i++)x2[i]=x0[i]+a0*e2[i];printf("x2[0]=%fx2[1]=%f",x2[0],x2[1]);if(g1(x2[0],x2[1])>=0&&g2(x2[0],x2[1])>=0&&g3(x2[0],x2[1])>=0){fx2=minfun(x2[0],x2[1]);printf("fx2=%lf",fx2);if(fx26、}elsea0=-a0;//Y正反方向;for(j=0;;){for(i=0;i<2;i++)x2[i]=x0[i]+a0*e2[i];printf("x2[0]=%fx2[1]=%f",x2[0],x2[1]);if(g1(x2[0],x2[1])>=0&&g2(x2[0],x2[1])>=0&&g3(x2[0],x2[1])>=0){fx22[j]=minfun(x2[0],x2[1]);printf("fx2=%lf",fx22[j]);if(fx22[j]7、0;j++;}//实现Y方向的多次搜索;elsebreak;}elsebreak;}if(h0>e)h0=0.5*h0;elsebreak;}printf("%lf%lf",x0[0],x0[1]);printf("fx[min]=%lf",fx0);}//输出结果,开始判断出去.