1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python牛顿法解非线性方程组_matlab实现牛顿迭代法求解非线性方程组.pdf

python牛顿法解非线性方程组_matlab实现牛顿迭代法求解非线性方程组.pdf

时间:2021-02-12 05:33:01

相关推荐

python牛顿法解非线性方程组_matlab实现牛顿迭代法求解非线性方程组.pdf

matlab实现牛顿迭代法求解非线性方程组.pdf

matlab 实现牛顿迭代法求解非线性方程组实现牛顿迭代法求解非线性方程组 已知非线性方程组如下 3*x1-cosx2*x3-1/20 x12-81*x20.12sinx31.060 exp-x1*x220*x310*pi-3/30 求解要求精度达到 0.00001 首先建立函数 fun 储存方程组编程如下将 fun.m 保存到工作路径中 function ffunx; 定义非线性方程组如下 变量 x1 x2 x3 函数 f1 f2 f3 syms x1 x2 x3 f13*x1-cosx2*x3-1/2; f2x12-81*x20.12sinx31.06; f3exp-x1*x220*x310*pi-3/3; ff1 f2 f3; 建立函数 dfun 用来求方程组的雅克比矩阵将 dfun.m 保存到工作路径中 function dfdfunx; 用来求解方程组的雅克比矩阵储存在 dfun 中 ffunx; dfdifff,x1;difff,x2;difff,x3; dfconjdf; 编程牛顿法求解非线性方程组将 newton.m 保存到工作路径中 function xnewtonx0,eps,N; con0; 其中 x0 为迭代初值 eps 为精度要求 N 为最大迭代步数 con 用来记录结果是否收敛 for i1N; fsubsfunx0,x1 x2 x3,x01 x02 x03; dfsubsdfunx0,x1 x2 x3,x01 x02 x03; xx0-f/df; for j1lengthx0; ili,jxj; end if normx-x0eps con1; break; end x0x; end 以下是将迭代过程写入 txt 文档文件名为 iteration.txt fiditeration.txt,w; fprintffid,iteration; for j1lengthx0 fprintffid, xd,j; end for j1i fprintffid,n6d ,j; for k1lengthx0 fprintffid, 10.6f,ilj,k; end end if con1 fprintffid,n 计算结果收敛; end if con0 fprintffid,n 迭代步数过多可能不收敛; end fclosefid; 运行程序 在 matlab 中输入以下内容 newton0.1 0.1 -0.1,0.00001,20 输出结果 ans 0.5000 0.0000 -0.5236 在 iteration 中查看迭代过程 iteration x1 x2 x3 1 0.490718 0.031238 -0.519661 2 0.509011 0.003498 -0.521634 3 0.500928 0.000756 -0.523391 4 0.500227 0.000076 -0.523550 5 0.500019 0.000018 -0.523594 6 0.500005 0.000002 -0.523598 7 0.500000 0.000000 -0.523599 计算结果收敛

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。