Newton Raphson with convergence control

14 ビュー (過去 30 日間)
Henrik
Henrik 2014 年 11 月 13 日
コメント済み: Geoff Hayes 2014 年 11 月 13 日
Hi!
I am wondering is someone please can help me with the while-loop in a program that should perform newton-raphson and to write the convergence (K) in the answer?
I have put the equation given in the problem in a function file called R and it's derivative in a function called Rd.
I have been told that K should be around 0.3-0.7
The correct x is 1,21952*10^-7
The code as it looks now:
x = 1; % Start guess
tolerance =10^(-6); %Tolerance given in the problem
nmax=20; %Maximum number of iterations
n=0; %Start value for number of iterations
disp(' K')
disp('---------------------------')
while abs(x)> tolerance && n<nmax;
f = R(x); %Function
fprim = Rd(x); %The functions derivative
dx = f/fprim;
dxOld = dx;
K = dx/dxOld.^2;
eps = abs(x)/abs(R(x));
disp (K)
x = x - dx;
n=n+1;
end
format long
x
  1 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 11 月 13 日
Henrik - are you sure that your R and Rd have been defined correctly? What is the behaviour that you are observing?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeNewton-Raphson Method についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by