Question
c++
Newton method for iteratively finding the root f(x) = 0. The equation is Where f(x) is the function, f(x) is the derivative
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include
#define EPSILON 0.0001 //tolerance
using namespace std;


double func(double x)
{
   return x*x*x - x*x + 2;
}

// Derivative of the above function which is 3*x^x - 2*x
double derivFunc(double x)
{
   return 3*x*x - 2*x;
}

// Function to find the root
void newtonRaphson(double x)
{
   int steps=0;
   double h = func(x) / derivFunc(x);
   while (abs(h) >= EPSILON)
   {
       h = func(x)/derivFunc(x);

       // x(i+1) = x(i) - f(x) / f'(x)
       x = x - h;
       cout<<"root is "<    cin>> x0;
   newtonRaphson(x0);
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
c++ Newton method for iteratively finding the root f(x) = 0. The equation is Where f(x)...
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