Help me with Matlab code on Newton-Raphson method to solve a system of nonlinear equations.
11 ビュー (過去 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, :));
0 件のコメント
回答 (1 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!