Newton for a 4x4 system of nonlinear eqns

Join the discussion
Registration is free. Start your own thread to ask a follow-up.
1 reply · 3K views
Moly
Messages
20
Reaction score
0
Hi All.
Can somebody give me a sample MATLAB code for Newton-Raphson Method for Nonlinear 4x4 System of Equations. I'm trying to set a very ugly one up and haven't seen NR before the beginning of this week. I've figured the NR for a single eqn but this is driving me nuts.
 
Physics news on Phys.org
Hi All. I think i figured it out... i am attaching the program below for a linear set of eqns... that was just to verify that all is working well... however, i was told that the method should converge in one iteration for a linear system, and for me it happens in 3.. am i doing something wrong here:

clear all
close all

syms x y z k
f1=x-2*y+0*z+3*k+2;
f2=0*x+y+0*z-4*k-7;
f3=0*x-0*y+z+0*k-6;
f4=0*x-0*y+0*z+k+3;

Jk=zeros(4,4);
Jk=[1 -2 0 3;
1 -1 0 -4;
1 -2 1 3;
1 -2 1 4];

x1=2; x2=-5; x3=-4; x4=-1;
xxold=[2;-5;-4;-1]
for i=1:4
F=[subs(f1, {x,y,z,k},{x1,x2,x3,x4});
subs(f2, {x,y,z,k},{x1,x2,x3,x4});
subs(f3, {x,y,z,k},{x1,x2,x3,x4});
subs(f4, {x,y,z,k},{x1,x2,x3,x4})];
xx=xxold-inv(Jk)*F;
x1=xx(1); x2=xx(2);x3=xx(3);x4=xx(4);
xxold=xx
end