Newton Raphson with convergence control

14 次查看(过去 30 天)
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 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by