Newton-Raphson method

조회 수: 7 (최근 30일)
viet le
viet le 2016년 9월 23일
답변: Meysam Mahooti 2019년 12월 5일
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

답변 (1개)

Meysam Mahooti
Meysam Mahooti 2019년 12월 5일

카테고리

Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by