logo资料库

坐标轮换法matlab程序.doc

第1页 / 共2页
第2页 / 共2页
资料共2页,全文预览结束
现代设计方法及其应用 matlab 程序作业(7.18) %A矩阵用于存储每一轮变换所得解 %沿e1方向搜索 源程序: %坐标轮换法 clear e=input('输入精度要求e:'); X=input('输入初始点:'); syms t s a=10*X(1,1)^2+106*X(2,1)^2+10*X(1,1)*X(2,1)+96*X(1,1)+100*X(2,1); k=1; e1=[1;0]; e2=[0;1]; A=X; C=X+t*e1; x1=C(1,1); x2=C(2,1); df=diff(10*x1^2+106*x2^2+10*x1*x2+96*x1+100*x2); t=solve(df); X=X+t*e1; C=X+s*e2; x1=C(1,1); x2=C(2,1); df=diff(10*x1^2+106*x2^2+10*x1*x2+96*x1+100*x2); s=solve(df); X=X+s*e2; A=[A X]; b=10*X(1,1)^2+106*X(2,1)^2+10*X(1,1)*X(2,1)+96*X(1,1)+100*X(2,1); a=[a b]; B=A(:,k+1)-A(:,k); while double(sqrt(B(1,1)^2+B(2,1)^2))>e %沿e2方向搜索 syms t s C=X+t*e1; %沿e1方向搜索 x1=C(1,1); x2=C(2,1); df=diff(10*x1^2+106*x2^2+10*x1*x2+96*x1+100*x2); t=solve(df); X=X+t*e1; C=X+s*e2; %沿e2方向搜索 x1=C(1,1); x2=C(2,1); df=diff(10*x1^2+106*x2^2+10*x1*x2+96*x1+100*x2); s=solve(df); X=X+s*e2; A=[A X];
b=10*X(1,1)^2+106*X(2,1)^2+10*X(1,1)*X(2,1)+96*X(1,1)+100*X(2,1); a=[a b]; B=A(:,k+1)-A(:,k); k=k+1; end Y=10*X(1,1)^2+106*X(2,1)^2+10*X(1,1)*X(2,1)+96*X(1,1)+100*X(2,1); A a fprintf('轮换次数k=%f\n',k); X Y %n次迭代得到X值矩阵 %n次迭代得到函数值数组 调试结果: >> CoordinateExchange 输入精度要求 e:0.001 输入初始点:[4;3] -63/10, A = [ 4, -94421088923/20199631360] [ -107575224677/428232184832] -37/212, 3, -9991/2120, -11209/44944, -2101267/449440, -445384479/95281280, -2393133/9528128, -507428321/2019963136, 1918, a = [ -45600924645285239537/192464673150894080, -2049487957296092615516553/8650132270093783531520] -22573759617/95281280, -447593/2120, -1014616480722073/4282321848320, 轮换次数 k=5.000000 X = [-94421088923/20199631360 -107575224677/428232184832] Y = -2049487957296092615516553/8650132270093783531520 机研 1203 班 宁晖 2012210138
分享到:
收藏