Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Newton for a 4x4 system of nonlinear eqns

  1. Jan 22, 2009 #1
    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.
     
  2. jcsd
  3. Jan 25, 2009 #2
    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Newton for a 4x4 system of nonlinear eqns
Loading...