Newton Raphson with convergence control

14 vues (au cours des 30 derniers jours)
Henrik
Henrik le 13 Nov 2014
Commenté : Geoff Hayes le 13 Nov 2014
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 commentaire
Geoff Hayes
Geoff Hayes le 13 Nov 2014
Henrik - are you sure that your R and Rd have been defined correctly? What is the behaviour that you are observing?

Connectez-vous pour commenter.

Réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by