Newton Raphson with convergence control
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Geoff Hayes
el 13 de Nov. de 2014
Henrik - are you sure that your R and Rd have been defined correctly? What is the behaviour that you are observing?
Respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!