File Exchange

image thumbnail

Newton-Raphson Method for 2 variables

version 1.0 (1.91 KB) by

Newton method for non-linear system of 2 variables (also solves linear system)



View License

This program calculates the roots of a system of non-linear equations in 2 variables. This a script file and you only have to write in the command windows ">>newton2v2", and the program ask for the functions and other elements that are necessary. What I mean "quotes" is single quotes,like this: ' .
I will be grateful for any comment.
I also have this program for 3, 4 ,5 variables and can be extended to any number of variables

Comments and Ratings (9)

Sandeep Soni

When i am running your code for following equations,roots are not correct .Kindly help me.
f1(x,y) = '(((1+2*x^2)/(1-x^2))+(4*(1-2*y^2)*sqrt(1-x^2)*(2+x^2))/((1-x^2)*(1-y^2)^0.5*(2+y^2)))'

f2(x,y) = '(((4*(y*(2+x^2)*(1-x^2)*sqrt(pi^2*(1-y^2)+4*y^2)))/(x*(2+y^2)*(1-y^2)*sqrt(pi^2*(1-x^2)+4*x^2))-1))'

The initial values are xo = 0.10 and yo = 0.10
The maximun number of iteration is k = 100
 and the tolerance is: 1.00e-007

The Root are:
x = 5.7355e+054 +5.3264e+053i
y = 5.7207e+054 +5.3127e+053i

Otherwise your code very excellent.

Sandeep Soni,


Saqib (view profile)


Saqib (view profile)

can u plz post the m file code for 4 variables?

EMRE before running the program try
>> syms x y

diff(f,n) means give me the nth derivative of f, and thats why it needs to be integer..


Ektor (view profile)

The first function? (between quotes) f1(x,y) = x+y
The second function? (between quotes)f2(x,y) = 2*x+y
??? Error using ==> diff
Difference order N must be a positive integer scalar.

Error in ==> newton2v2 at 24
       gradf1 = [diff(f1name,'x') diff(f1name,'y')] ;

Why is this happening?


Emre (view profile)

can you give any input examples?


Emre (view profile)

I can not enter my functions, it says
"??? Error using ==> input
Undefined function or variable 'x'.

Error in ==> Untitled at 22
       f1name = input('The first function? (between quotes) f1(x,y) = ');"
please help


xingyu (view profile)

Hi where can I get the propram for 4 variables ?

thanx for this code.....

MATLAB Release
MATLAB 6.1 (R12.1)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video