error in nonlinear system

5 visualizaciones (últimos 30 días)
king skiler
king skiler el 7 de Nov. de 2018
Comentada: Torsten el 8 de Nov. de 2018
please ! can you detect the errors of this code? and how i can get the answer correctly!
fun = @(x) [x(1) ^ 2 + x(2) ^ 2 + x(3) ^ 2 - 1; ...
x(1) ^ 2 + x(3) ^ 2 - 0.25; ...
x(1) ^ 2 + x(2) ^ 2 + 4 * x(3)];
J = @(x) [ 2 * x(1) + 2 * x(2) + 2 * x(3) ; ...
2 * x(1) + 2 * x(3); ...
2 * x(1) + 2 * x(2) - 4 ];
x0 = [1;1;1]'; tol= 0.00001; maxit= 10;
xold = x0; iter=1;
while (iter<= maxit)
y= -feval(J,xold)\ feval(f,xold);
xnew=xold + y';
dif = norm(xnew-xold);
disp(iter); disp(xnew); disp(dif);
if dif <= tol
x=xnew ;
disp (' Newton method has converged '), return;
else
xold= xnew;
end
iter = iter + 1;
disp(' itre xnew dif')
end
disp('Newton method did not converge')
x = xnew ;

Respuestas (1)

Torsten
Torsten el 7 de Nov. de 2018
Editada: Torsten el 7 de Nov. de 2018
Why is your Jacobian (3x1) and not (3x3) ?
And replace
y = -feval(J,xold)\ feval(f,xold);
by
y = -J(xold)\fun(xold)
Best wishes
Torsten.
  2 comentarios
king skiler
king skiler el 7 de Nov. de 2018
still not working , because adding matrix wrong in the line of : xnew=xold+y;
Torsten
Torsten el 8 de Nov. de 2018
For me, it works:
fun = @(x) [x(1) ^ 2 + x(2) ^ 2 + x(3) ^ 2 - 1; ...
x(1) ^ 2 + x(3) ^ 2 - 0.25; ...
x(1) ^ 2 + x(2) ^ 2 + 4 * x(3)];
J = @(x) [ 2 * x(1) , 2 * x(2) , 2 * x(3) ; ...
2 * x(1),0, 2 * x(3); ...
2 * x(1) , 2 * x(2), 4 ];
x0 = [1;1;1]'; tol= 0.00001; maxit= 100;
xold = x0; iter=1;
while (iter<= maxit)
y= -J(xold)\ fun(xold);
xnew=xold + y';
dif = norm(xnew-xold);
disp(iter); disp(xnew); disp(dif);
if dif <= tol
x=xnew ;
disp (' Newton method has converged '), return;
else
xold= xnew;
end
iter = iter + 1;
disp(' itre xnew dif')
end
disp('Newton method did not converge')
x = xnew ;

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by