您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 5matlab牛顿法求解非线性方程组的数值解问题
P184牛顿法求解非线性方程组的数值解问题:——5牛顿法只可以求解方程个数和未知数个数相等的非线性方程组;;;程序:注意xx1x2的形式:程序一(NewtonS.m)functions=NewtonS(x,eps)ifnargin==1eps=1e-6;elseifnargin1error('pleaseinputtwoshu');return;endendn=1;a=[0];x1=NewtonSfun1(x);a=[n,x,x1];x2=-NewtonSdfFun(x);x3=inv(x2);x0=x1*x3;whilenorm(x0)=epsx=x0+x;x1=NewtonSfun1(x);n=n+1;a=[a;n,x,x1];x2=-NewtonSdfFun(x);x3=inv(x2);x0=x1*x3;enda程序2M文件(NewtonSfun1.m)求解方程组的函数值:functiony=NewtonSfun1(x)y(1)=x(1)*x(1)-10*x(1)+x(2)*x(2)+8;y(2)=x(1)*x(2)*x(2)+x(1)-10*x(2)+8;y=[y(1),y(2)];程序3M文件求解方程组对每个参数的导数值(NewtonSdfFun.m)functiony=NewtonSdfFun(x)y(11)=2*x(1)-10;y(12)=2*x(2);y(21)=x(2)*x(2)+1;y(22)=2*x(1)*x(2)-10;y=[y(11),y(13);y(21),y(22)];调用语句:NewtonS([0.8,0.88])结果:a=迭代次数y1函数值y2函数值y1导数值y2导数值1.00000.80000.88001.41440.61952.00000.98360.95210.03790.35423.00000.99870.99570.00200.03194.00000.99990.99970.00000.00255.00001.00001.00000.00000.00026.00001.00001.00000.00000.0000另一个简便方法:程序一(NewtonS1.m):functions=NewtonS1(x,eps)ifnargin==1eps=1e-6;elseifnargin1error('pleaseinputtwoshu');return;endendn=1;a=[0];[ffdff]=NewtonSfun(x);x1=ff;a=[n,x,x1];x2=-dff;x3=inv(x2);x0=x1*x3;whilenorm(x0)=epsx=x0+x;[ffdff]=NewtonSfun(x);x1=ff;n=n+1;a=[a;n,x,x1];x2=-dff;x3=inv(x2);x0=x1*x3;enda将方程组的函数值和方程组的导数值写到同一个M文件中,借助于符号函数的应用,subs(函数,old,new)docsubs程序二(NewtonSfun.m)function[ffdff]=NewtonSfun(x)symsx1x2symsy1y2symsysymsy11y12symsy21y22dyy1=x1*x1-10*x1+x2*x2+8;y2=x1*x2*x2+x1-10*x2+8;y=[y1y2];ff=subs(y,[x1,x2],x);y11=diff(y1,x1);y12=diff(y1,x2);y21=diff(y2,x1);y22=diff(y2,x2);dy=[y11,y12;y21,y22];dff=subs(dy,[x1,x2],x);调用语句:NewtonS1([0.8,0.88])结果:a=1.00000.80000.88001.41440.61952.00000.99190.99140.04760.05273.00001.00001.00000.00010.00024.00001.00001.00000.00000.0000
本文标题:5matlab牛顿法求解非线性方程组的数值解问题
链接地址:https://www.777doc.com/doc-2928720 .html