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 Center および File ExchangeNewton-Raphson Method についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by