Code covered by the BSD License  

Highlights from
Newton-Raphson Method for 2 variables

5.0 | 2 ratings Rate this file 27 Downloads (last 30 days) File Size: 1.91 KB File ID: #27120

Newton-Raphson Method for 2 variables


Jesus Hernandez


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

| Watch this File

File Information

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

MATLAB release MATLAB 6.1 (R12.1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
23 Mar 2014 Sandeep Soni

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,

15 Dec 2011 Saqib


15 Dec 2011 Saqib



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

Comment only
20 Nov 2011 Vagelis Kounis

Vagelis Kounis

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..

Comment only
18 Nov 2011 Ektor


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?

Comment only
12 Oct 2011 Emre


can you give any input examples?

Comment only
12 Oct 2011 Emre


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

Comment only
31 Mar 2011 xingyu


Hi where can I get the propram for 4 variables ?

Comment only
25 Feb 2011 chanchal gupta

chanchal gupta

thanx for this code.....

Comment only

Contact us