首页 > 代码库 > 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
matlab Newton method
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。