Rewton Rraphson metod for systems
Show older comments
I found this in the internet, but it gives me an error.
"Error using newtonm (line 16) Not enough input arguments."
I have no idea which could be the reason for that problem. I am very bad at this, please help! Thanks! :)
Additional information: the first one is a script and the other two are functions, and of course all of the are in the same folder.
function [x,iter] = newtonm(x0,f,J)
x0=input('enter the value of x0 please ');
N=100;
epsilon=1e-10;
maxval=10000.0;
xx=x0;
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
-----------------------------------------------------------------------------
function [f] = f2(x)
% f2(x) = 0, with x = [x(1);x(2)]
% represents a system of 2 non-linear equations
f1=x(1)^2+x(2)^2-50;
f2=x(1)*x(2) -25;
f=[f1;f2];
-----------------------------------------------------------------------------
function [J] = jacob2x2(x)
% Evaluates the Jacobian of a 2x2
% system of non-linear equations
J(1,1)=2*x(1);J(1,2)=2*x(2);
J(2,1)=x(2);J(2,2)=x(1);
Answers (0)
Categories
Find more on Newton-Raphson Method in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!