蒙特卡罗方法求解有约束的非线性规划问题的matlab程序.doc
蒙特卡罗方法求解有约束的非线性规划问题的matlab程序首先我们说明一下观察函数fx,它恰好可以应用雅克比矩阵来计算得到clear;symsx1x2x3x4x5;y1x1*x2x3x421/2/x5x321/2;fsimplejacobiany*[x1;x2;x3;x4;x5];然后将得到的f表达式前面加上x1,x2,x3,x4,x5fx1,x2,x3,x4,x5-1/4*x3*2*x1*x2*x3x53*x322*x42*x3/x5x32/x5x32x1*x2x3x421/2*x5x321/2/x1*x2x3x421/2;作为下面程序中的f即可,已经验证过结果仍然差不多。下面程序中的f仍为原程序所给的f。matlab蒙特卡罗方法程序(相关原理参见附件文献)clear;fx1,x2,x3,x4,x5-x3*3*x322*x3*x422*x1*x2*x3x5.../4*x5x42x3x1*x21/2x32/x32x51/2*x32x52*x42x3x1*x21/2;MINinf;LIMIT10000;whileLIMIT0 x34.5*rand0.5;将【0,1】区间上的随机数转化到【0.5,5】上的随机数,下面其余数类同x42*rand1;x53*rand1;x14.5*rand0.5;x24.5*rand0.5;whilex1x221x1x220 x34.5*rand0.5;x42*rand1;x53*rand1;x14.5*rand0.5;x24.5*rand0.5;ifx1x221x1x220 x34.5*rand0.5;x42*rand1;x53*rand1;x14.5*rand0.5;x24.5*rand0.5;whilex1x2210 x14.5*rand0.5;x24.5*rand0.5;end;x1x1;x2x2;x3x3;x4x4;x5x5;tempfx1,x2,x3,x4,x5;iftemp10时,再次令设x14.5*rand0.5;x24.5*rand0.5;重新进行while循环,只有当条件上面条件不满足才完成内层的while循环,接着执行后面的语句。所以内层while循环完全等效于如下if判断clear;fx1,x2,x3,x4,x5-x3*3*x322*x3*x422*x1*x2*x3x5.../4*x5x42x3x1*x21/2x32/x32x51/2*x32x52*x42x3x1*x21/2;MINinf;LIMIT10000;k0;whileLIMIT0 x34.5*rand0.5;x42*rand1;x53*rand1;x14.5*rand0.5;x24.5*rand0.5;ifx1x2210continue;end;x1x1;x2x2;x3x3;x4x4;x5x5;tempfx1,x2,x3,x4,x5;iftempMINMINtemp;x0x;end;LIMITLIMIT-1;end;MIN,x0