% Matlab script to illustrate Newton's method
% to solve a nonlinear equation
% this particular script finds the square root of a number M
% (input by the user)
% note that the function we are trying to zero is f(x) = x^2 - M.
% its derivative is f'(x) = 2*x.
% these functions are hard-coded in the script.
format long
% get user input
M = input('Please enter the number whose square root you want: ')
x0 = input('Please enter starting guess: ')
% iteration counter
k = 1
% compute first Newton iterate to enter loop
x = x0 - (x0^2-M)/(2*x0)
disp('Hit return to continue')
pause
while abs(x-x0) > eps*abs(x),
% reset guess to old iterate
x0 = x;
% increment iteration counter
k = k + 1
% compute and display Newton iterate
x = x0 - (x0^2-M)/(2*x0)
disp('Hit return to continue')
pause
end
matlab Newton method
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:JAVA获取操作系统的信息
下一篇:Markdown 语法的简要规则
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
优化算法——牛顿法(Newton Method)
一、牛顿法概述
优化算法 牛顿法 机器学习 Math Java
















