Question

(C++) Solve the following polynomial using Newton’s method.             X4+ 2x3-9x2-2x +8 = 0 For a root...

(C++)

Solve the following polynomial using Newton’s method.

            X4+ 2x3-9x2-2x +8 = 0

For a root that lies between x=-2 and x= -10.

Print out for each iteration the current x, stop when the solution is within 10-5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//                     f( x(n) )

// x(n+1) = x(n) - -----------------

//                    f'( x(n) )

// find root of f(x) = x^4 + 2x^3 -9x^2 -2x +8 upto 3 decimal places

// So, f'(x) = 4x^3 + 6x^2 - 18x

// f(-10) = 7128

// f(-2) = -24

// as the sign is different, so the root lies in between [ -10 , -2 ]

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

    int n = 5;

   

    // initially set the x(n) root to right bound

    double x_n = -10;

   

    // calculate f(x(n))

    double f_x = pow( x_n, 4 ) + 2 * pow( x_n, 3 ) - 9 * pow( x_n, 2 ) - 2 * x_n + 8;

   

    // calculate f'(x(n))

    double f_der_x = 4 * pow( x_n, 3 ) + 6 * pow( x_n, 2 ) - 18 * x_n;

   

    // calculate x(n+1)

    double x_n_1 = x_n - ( f_x / f_der_x );

   

    while(true)

    {

        // if the root is correct upto n decimal places

       if( abs( x_n_1 - x_n ) < pow( 0.1, n ) )

           break;

       

        // set x(n+1) as the x(n) th root

        x_n = x_n_1;

       

        cout<<"x : "<<x_n<<endl;

       

        // calculate f(x(n))

        f_x = pow( x_n, 4 ) + 2 * pow( x_n, 3 ) - 9 * pow( x_n, 2 ) - 2 * x_n + 8;

   

        // calculate f'(x(n))

        f_der_x = 4 * pow( x_n, 3 ) + 6 * pow( x_n, 2 ) - 18 * x_n;

   

        // calculate x(n+1)

        x_n_1 = x_n - ( f_x / f_der_x );

    }

   

    cout<<"Root lies at x = "<<x_n;

   

    return 0;

}


Sample Output

Add a comment
Know the answer?
Add Answer to:
(C++) Solve the following polynomial using Newton’s method.             X4+ 2x3-9x2-2x +8 = 0 For a root...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT