Henrik - are you sure that your R and Rd have been defined correctly? What is the behaviour that you are observing?
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
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!