实用 MATLAB教学资料-15-16非线性方程组.pptVIP

  • 12
  • 0
  • 约9.64千字
  • 约 107页
  • 2017-06-04 发布于浙江
  • 举报

实用 MATLAB教学资料-15-16非线性方程组.ppt

小结 roots 求多项式方程f(x)=0的全部根,包括实根和复根。 solve 突出功能是求解多项式方程和方程组全部解析解。 fzero 求单变量非线性方程的实根,一次求一个根。必须给初值。 fsolve 求非线性方程(组)的实数或复数解,一次返回一个解。必须给初值。 vpasolve 对多项式方程,可求得所有解包括复根。对非多项式方程(组)给出一个解。可不给初值。 小结 MuPAD Notebook ? 7.3.2非线性方程(组)求解的MATLAB实现 7.3 非线性方程(组)的求解 二、数值解法的MATLAB程序 MATLAB程序 宋叶志,贾东永 编著,MATLAB数值分析与应用,北京:机械工业出版社,2009年7月第1版 随书光盘登录202.113.6.235,有视频讲解 迭代计算的终止准则 i=1,2,…,n 或向量范数形式 例 Newton基本格式求解 (1)Newton迭代法基本格式,命名为new_ton.m function [x,n,data]=new_ton(x0,tol) if nargin==1%如果用户只给了x0,没有指定tol,程序使用缺省值 tol=1e-10;%误差限 end Nmax=1000;%设置最大迭代次数 n=1;%n为计算次数 x1=x0-inv(df1(x0))*f1(x0);%x0是用户输入的迭代初值 while (norm(x1-x0)tol)(nNmax) x0=x1; x1=x0-inv(df1(x0))*f1(x0); n=n+1; data(:,n)=x1; %存储每次迭代计算结果 end x=x1; (2)定义待解非线性方程组 function y=f1(x) y(1)=x(1)*x(1)-2*x(1)-x(2)+0.5; y(2)=x(1)^2+4*x(2)*x(2)-4; y=[y(1);y(2)]; 命名为f1.m (3)定义非线性方程组的Jacobi矩阵 function y=df1(x) y(1,1)=2*x(1)-2; y(1,2)=-1; y(2,1)=2*x(1); y(2,2)=8*x(2); y=[y(1,1) y(1,2);y(2,1) y(2,2)]; 命名为df1.m (4)编写脚本文件,解方程组 clear all clc x0=[1;1]; [x,n,data]=new_ton(x0); x n 命名为newton_main.m 迭代计算编程注意 1、最好在脚本文件最开始加上clear all 。 2、设置最大迭代次数,防止不收敛的时候进入无穷循环状态。必要时可以使用Ctrl+C强行终止运行。 ?3、输出信息中最好包括exitflag,以便知晓终止运行的原因,是收敛结束,还是超出最大迭代计算次数而结束。 作业 使用fsolve求解, 要求精度满足 (6) exitflag —计算终止信息,可选 exitflag the reason the algorithm terminated 1 Function converged to a solution x. 2 Change in x was smaller than the specified tolerance 3 Change in the residual was smaller than the specified tolerance. 4 Magnitude of search direction was smaller than the specified tolerance. exitflag =1~4 收敛 [x,fval,exitflag,output]=fsolve(fun,x0,options) 建议输出 exitflag the reason the algorithm terminated 0 Exceeded MaxIter or MaxFunEvals -1 Output function terminated the algorithm. -2 Algorithm appears to be converging to a point that is not a root. -3 Trust region radius became too small . -4 Line search cannot sufficiently decrease the residual along the current search direction. (6) exitflag —计算终止信息 [x,fval,exitflag,output]=fsolve(

文档评论(0)

1亿VIP精品文档

相关文档