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

This is a discussion on NEED MAJOR HELP WITH HW....Newton-Raphson method within the C Programming forums, part of the General Programming Boards category; Code: Find on the next page an outline for a C program that solves two nonlinear equations f1(x,y) = 0 ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    30

    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. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    so your telling me once i learn that my program will be a while loop??

  4. #4
    Nub SWE
    Join Date
    Mar 2008
    Location
    Dallas, TX
    Posts
    133
    It doesn't necessarily have to be a while loop. A for loop, a while loop, whatever.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    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. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by clezzie View Post
    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. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    tabstop theres no formula i never ever learned this ............i went to my ta and he said this ........ was hard

  8. #8
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    http://www.ugrad.math.ubc.ca/coursed...ox/newton.html

    I'm guessing this assignment requires the newton approximation method?
    =========================================
    Everytime you segfault, you murder some part of the world

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 06:50 PM
  2. Newton Raphson method code
    By taebin in forum C Programming
    Replies: 2
    Last Post: 10-17-2004, 02:44 AM
  3. Newton Raphson method code
    By taebin in forum C++ Programming
    Replies: 2
    Last Post: 10-16-2004, 03:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21