資源描述:
《matlab求解超定方程組實例》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、Matlab求解超定方程組實例對于超定方程組,特別是非線性方程組,可以用Matlab基于最小二乘算法來進行求解,例如,求解下列方程組:一個三個未知數(shù),九個方程的非線性方程組:cos(x3)*sin(x2)*sin(x1)-sin(x3)*cos(x1)=-0.9944;sin(x3)*sin(x2)*sin(x1)+cos(x3)*cos(x1)=-0.0870;cos(x2)*sin(x1)=-0.0606;cos(x3)*sin(x2)*cos(x1)+sin(x3)*sin(x1)=0.0349;sin(x3)*
2、sin(x2)*cos(x1)-cos(x3)*sin(x1)=-0.8085;cos(x2)*cos(x1)=0.5875;os(x3)*cos(x2)=-0.1001;sin(x3)*cos(x2)=0.5821;-sin(x2)=0.8070;代碼%Bylyqmathfunctionmain()clc;clearall;closeall;%cos(x3)*sin(x2)*sin(x1)-sin(x3)*cos(x1)=-0.9944;%sin(x3)*sin(x2)*sin(x1)+cos(x3)*cos(x1)
3、=-0.0870;%cos(x2)*sin(x1)=-0.0606;%cos(x3)*sin(x2)*cos(x1)+sin(x3)*sin(x1)=0.0349;%sin(x3)*sin(x2)*cos(x1)-cos(x3)*sin(x1)=-0.8085;%cos(x2)*cos(x1)=0.5875;%os(x3)*cos(x2)=-0.1001;%sin(x3)*cos(x2)=0.5821;%-sin(x2)=0.8070;x0=[0.30.40.5]????????????[x,resnorm]=lsqn
4、onlin(@test_fun,x0)F=test_fun(x)functionF=test_fun(x)x1=x(1);x2=x(2);x3=x(3);F(1)=cos(x3)*sin(x2)*sin(x1)-sin(x3)*cos(x1)+0.9944;F(2)=sin(x3)*sin(x2)*sin(x1)+cos(x3)*cos(x1)+0.0870;F(3)=cos(x2)*sin(x1)+0.0606;F(4)=cos(x3)*sin(x2)*cos(x1)+sin(x3)*sin(x1)-0.0349;F
5、(5)=sin(x3)*sin(x2)*cos(x1)-cos(x3)*sin(x1)+0.8085;F(6)=cos(x2)*cos(x1)-0.5875;F(7)=cos(x3)*cos(x2)+0.1001;F(8)=sin(x3)*cos(x2)-0.5821;F(9)=-sin(x2)-0.8070;結(jié)果x0=??0.3000??0.4000??0.5000Localminimumfound.Optimizationcompletedbecausethesizeofthegradientislessthant
6、hedefaultvalueofthefunctiontolerance.x=??-0.1028?-0.9390??1.7411resnorm=?5.4490e-009F=?1.0e-004*?Columns1through7??0.3522??0.1842?-0.0442??0.1487??0.2260?-0.0936??0.0183?Columns8through9??-0.3600?-0.4160>>?可以發(fā)現(xiàn),誤差在1.0e-004級別,還是可以接受的。