When I use newtons method to find the roots of a system of equations I get the following error message:
"Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.625479e-33. > In new (line 16)"
Any ideas why I get this error message? I know about singular matrices and the inverse thing but could this really have to do anything with that? If so, how? What difference can I make to the code? It says line 16, which is dx = -J\f;
. But I just follow along with my numerical methods textbook. Something must be wrong, but the exercise says "use Newtons Method" so I guess this should work. I hope someone can help me.
x = [0 0 pi/2]';
maxiter = 10;
iter = 0;
dxnorm = 1;
results = cell(maxiter + 1, 2); % Preallocate results array
while dxnorm > 0.5e-4 && iter <= maxiter
f = [cos(x(1)) + cos(x(2)) + cos(x(3))-2; ...
sin(x(1)) + sin(x(2)) + sin(x(3)); ...
tan(x(1)) - 2.*tan(x(2)) + tan(x(3)); ...
];
J = [-sin(x(1)), -sin(x(2)), -sin(x(3)); ...
cos(x(1)), cos(x(2)), cos(x(3)); ...
tan(x(1)).^2 + 1, -2*tan(x(2)).^2 - 2, tan(x(3)).^2 + 1 ...
];
dx = -J\f;
results{iter + 1, 1} = x;
x = x + dx;
dxnorm = norm(dx,inf);
results{iter + 1, 2} = dxnorm;
iter = iter + 1;
end
x, iter
J~=0
then use other method. – Ander Biguripinv(J-lambda*eye(size(J)))
where lambda is some relaxation parameter instead. – user2457516J\f
solfesAx=b
problem with the rigth choice of algorithm. – Ander Biguri