# Thread: NEED MAJOR HELP WITH HW....Newton-Raphson method

1. ## NEED MAJOR HELP WITH HW....Newton-Raphson method

Code:
Find on the next page an outline for a C program that solves two nonlinear equations
f1(x,y)  =  0
f2(x,y)  =  0

for x and y using the Newton-Raphson method.

Complete this program and obtain the solution to the given equations.  Your program output should resemble the format given below.  You need print the solution  and corresponding function values only at the final iteration when either the solution is obtained or the maximum number of iteration is exceeded with no solution.  Exercise the program to show these two cases.

Sample program output:  (when program converges)

Please enter initial approximations close to solution!
For this EXAMPLE type : 2.0 0.25
2 .25
-----------------------------------------------------
The initial approximation are : 2.000000 0.250000
------------------------------------------------------
At the iteration number …. :    x = …     y = …

The function values are : 0.000000 0.000000
------------------------------------------------------
The solution was found with the desired tolerance !

Sample program output: (when program does not converge)

Please enter initial approximations close to solution!
For this EXAMPLE type : 2.0 0.25
7 1
-----------------------------------------------------
The initial approximation are : 7.000000 1.000000
------------------------------------------------------
At the iteration number …. :  x = …     y = …

The function values are :     f1= …   f2 = …
------------------------------------------------------
The max. number of iterations was exceeded!
Code:
/*      PROGRAM OUTLINE:  Newton-Raphson Method in 2-Dimensions

To solve:
0 = f_1 (x,y) =  x*x  -  2.0*x    -   y    + 0.5

0 = f_2 (x,y) =  x*x  +  4.0*y*y  -  4.0

given one initial approximation  (p_0, q_0)  and using
Newton-Raphson iteration.                                */

/* User has to supply SIX functions named :

f1function:  this is the function f_1(x,y)

f2function:  this is the function f_2(x,y)

d11function:  partial derivative of f_1 wrsp to x

d12function:  partial derivative of f_1 wrsp to y

d21fnction:   partial derivative of f_2 wrsp to x

d22function:  partial derivative of f_2 wrsp to y

/*  define prototype for USER-SUPPLIED functions  */

double f1function  (double x, double y);
double f2function  (double x, double y);
double d11function (double x, double y);
double d12function (double x, double y);
double d21function (double x, double y);
double d22function (double x, double y);

/* -------------------------------------------------------- */

void main()

{

}   /* End of main program */
Where Do I Start?????

2. You need to make sure you know what the Newton-Raphson method is, the description of which I don't see in your cut'n'paste. You should have a way to get a better approximation, f_n, based on the approximation you currently have, f_n-1. And you keep going until you're done.

3. so your telling me once i learn that my program will be a while loop??

4. It doesn't necessarily have to be a while loop. A for loop, a while loop, whatever.

5. ok i think i understand the Newton Raphson...correct me if im wrong...so i will take an initial guess and plug it in and it will keep looping until i get to the orignal answer. my thing is how would i do this and where will i start from??

6. Originally Posted by clezzie
my thing is how would i do this and where will i start from??
(1) There is a formula. If somehow it was omitted from your assignment, it is almost certainly then in your textbook.

(2)
Please enter initial approximations close to solution!

7. tabstop theres no formula i never ever learned this ............i went to my ta and he said this ........ was hard

I'm guessing this assignment requires the newton approximation method?

9. On the other hand, I myself am pretty sure that Newton's method is trivial. Granted, it's not as trivial in two dimensions as it is in one. Look it up on Wikipedia, then, but the basics for one dimension is:
x_n+1 = x_n - f(x_n)/f'(x_n), where f' is the derivative of f. Continue until tired, or until f(x_n) is sufficiently close to 0.

And for two:
x_n+1 = x_n - (J^-1)F(x_n)
where F(x_n) is your function (represented in your code above by f1 and f2), and J is your Jacobian matrix of derivatives (the 2x2 matrix d11, d12, d21, d22). Continue until tired, or until F(x_n) is sufficiently close to 0. Multiplying the inverse of a 2x2 matrix by a 2x1 vector is not very hard algebra and you would probably code that in directly.