第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > matlab newton method matlab Newton method

matlab newton method matlab Newton method

时间:2018-06-14 02:46:17

相关推荐

matlab newton method matlab Newton method

% 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

原文:/yfceshi/p/6885967.html

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