Home / Expert Answers / Computer Science / attached-below-is-the-c-nbsp-code-i-wrote-to-find-four-roots-of-a-polynomial-equation-nbsp-nbsp-pa524

(Solved): Attached below is the C++ code I wrote to find four roots of a polynomial equation  & ...



Attached below is the C++ code I wrote to find four roots of a polynomial equation    using Newton's Method. using the template given down below (photo) please convert the code that used the Newtons Method into the Secant Method following the template of the picture provied.

#include

#include

using namespace std;

int main()

{

       double x, d, fx, fpx;

       double xtol = 0.000001, ftol = 0.000001;

       int nmax = 100;

       char answer;

       cout << "This program finds roots of f(x)=-x^4+20x^2-4x-50 using Newton method" << endl;

       cout << " Do you want to find first ROOT? Y or N ";

       cin >> answer;

       while (answer == 'Y')

       {

             cout << "Enter inital x values :";

             cin >> x;

             cout << setw(6) << "n" << setw(10) << "x" << setw(12) << "f(x)" << endl;

             for (int n = 1;n <= nmax;n++)

             {

                    fx = -pow(x, 4) + 20 * pow(x, 2) - 4 * x - 50;

                    fpx = -4 * pow(x, 3) + 40 * x - 4;

                    d = fx / fpx;

                    x = x - d;

                    cout << setw(6) << n << setw(10) << setprecision(4)<< fixed<< x << setw(12) << setprecision(5)<

                    if (abs(d) <= xtol || abs(fx) <= ftol)

                    {

                           cout << "Root is :" << x << endl;

                           break;

                    }

             }

             cout << "No roots in this interval" << endl;

             cout << " Do you want to find next ROOT? Y or N ";

             cin >> answer;

       }

      

       return 0;

}

 

 

Need to code follow this C++ template

THE SECANT METHOD
Algorithm: Given f, xo, X, (two initial points), xtol, ftol, nmax
for n = 1 : nmax
+ X 1
-
d+ (x,-xo)/(fx,-

THE SECANT METHOD Algorithm: Given f, xo, X, (two initial points), xtol, ftol, nmax for n = 1 : nmax + X 1 - d+ (x,-xo)/(fx,-fxo)fx, ?? fxor fx, X, x,-d fx, + f(x,) if (d. S xtol or f(x)] s ftol, then roof X1 X, R return end end roof + X1


We have an Answer from Expert

View Expert Answer

Expert Answer


#include #include using namespace std; double secant_method(double ,double ,double ,int* ); double f(double ); int main() { double x1,x2,e; int iteration_no=0; cout<<"\nEnter the first initial approximation: "; c
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe