Help me with Matlab code on Newton-Raphson method to solve a system of nonlinear equations.

22 visualizaciones (últimos 30 días)
I want to approximate the zeros of the following nonlinear system, using N-R method:
f(x,y)=x+y^9/3+x^{243}/9+y^{2187}/27=0;
g(x,y)=y+x^{27}/3+y^{243}/9+x^{6561}/27=0.
I have tried with the following Matlab code. But I am getting error. Can you please help me out ?
close all; clc,clear
% Newton Raphson solution of two nonlinear algebraic equations
xy = [-1 -1]; % initial guesses
iter=0;
maxiter=100;
xy_N = 0.5;
TOL = 0.05;
error1 = [1, 1];
f = zeros(iter, 2);
error = zeros(iter, 2);
% begin iteration
while xy_N>TOL
iter=iter+1;
x = xy(1);
y = xy(2);
% calculate the functions
f(iter,:) = [x+y^9/3+x^{243}/9+y^{2187}/27; y+x^{27}/3+y^{243}/9+x^{6561}/27];
% calculate the Jacobian
J= [1+27*x^{242}, 3*y^8+81*y^{2186}; 9*x^{26}+24*x^{6560}, 1+27*y^{242}];
xy_new = xy - ((J)\f(iter,:)')';
error1=abs(xy_new-xy);
error(iter,:)=error1;
% Calculate norm:
xy_N = norm(f(iter,:));
XYN(iter) = xy_N;
xy=xy_new;
%iter=iter+1;
if (iter > maxiter)
fprintf('Did not converge! \n', maxiter);
break
end
end
if iter<maxiter
f(iter+1:end,:)=[];
end
% Print results
fprintf('Number of iterations is: %f \n ', iter)
fprintf('Final values of [x, y] = %f %f \n', xy(end, :));
fprintf('Final values of EQN: %f %f \n', f(end, :));
fprintf('Final values of ERROR: %f %f \n', error(end, :));

Respuestas (1)

Ahmad
Ahmad el 30 de Abr. de 2022
why you use { } ?
this is for cell type
  8 comentarios
Mabud Sarkar
Mabud Sarkar el 1 de Mayo de 2022
No there are more 3 zeros nearest to (-1,1), (1,-1) and (-1,-1). Please see the answer of @Cesareo here

Iniciar sesión para comentar.

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by