Newton-Raphson method

14 visualizaciones (últimos 30 días)
viet le
viet le el 23 de Sept. de 2016
Respondida: Meysam Mahooti el 5 de Dic. de 2019
I have a problem "find the steady-state solution of the following plant equation by using MATLAB codes", (Newton-Raphson method) ~~~ many thanks
This is Newton-Raphson code
function [x,iter] = newtonm(x0,f,J)
% Newton-Raphson method applied to a system of linear equations f(x) = 0,
% given the jacobian function J, with J = del(f1,f2,...,fn)/del(x1,x2,...,xn)
% x = [x1;x2;...;xn], f = [f1;f2;...;fn] x0 is an initial guess of the solution
N = 100; % define max. number of iterations
epsilon = 1e-10; % define tolerance
maxval = 10000.0; % define value for divergence
xx = x0; % load initial guess
while (N>0)
JJ = feval(J,xx);
if abs(det(JJ))<epsilon
error('newtonm - Jacobian is singular - try new x0');
abort;
end;
xn = xx - inv(JJ)*feval(f,xx);
if abs(feval(f,xn))<epsilon
x=xn;
iter = 100-N;
return;
end;
if abs(feval(f,xx))>maxval
iter = 100-N;
disp(['iterations = ',num2str(iter)]);
error('Solution diverges');
abort;
end;
N = N - 1;
xx = xn;
end;
error('No convergence after 100 iterations.');
abort;
% end function

Respuestas (1)

Meysam Mahooti
Meysam Mahooti el 5 de Dic. de 2019

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by