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

조회 수: 19 (최근 30일)
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, :));

답변 (1개)

Ahmad
Ahmad 2022년 4월 30일
why you use { } ?
this is for cell type
  댓글 수: 8
Mabud Sarkar
Mabud Sarkar 2022년 5월 1일
No there are more 3 zeros nearest to (-1,1), (1,-1) and (-1,-1). Please see the answer of @Cesareo here

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by