作业帮 > 英语 > 作业

matlab中用牛顿法求方程的根

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:英语作业 时间:2024/06/04 01:59:03
matlab中用牛顿法求方程的根
用matlab求解以下问题:
用牛顿法求解方程x=e^-x在x0=0.5附近的根(ε=10^-5)
matlab中用牛顿法求方程的根
代码如下:
function rtn=newton1(fx,dfx,x0,tol,N)
% Newton Method
% The first parameter fx is a external function with respect to viable x.
% The second parameter dfx is the first order diffential function of fx.
% x0 is initial iteration point.
% tol is the tolerance of the loop.
% N is the maximum number of iterations.
x=x0;f0=eval(fx);df0=eval(dfx);
n=0;
disp(' [ n xn xn+1 fn+1 ]');
while nfx='x-exp(-x)';
>>dfx='1+exp(-x)';
>>newton1(fx,dfx,.5,10^(-5),10)
[ n xn xn+1 fn+1 ]
0 0.5000 0.5663 -0.0013
1.0000 0.5663 0.5671 -0.0000
2.0000 0.5671 0.5671 -0.0000
3.0000 0.5671 0.5671 -0.0000
The procedure was successful.
最后求出的根为:0.5671