I have an assignment that I need to write for my C++ class and I just am not getting it. I have read my teachers powerpoint and I have looked for examples and none of it has helped. Here is what she is asking for and I will put my code below.
Write C++ code using the Newton-Raphson method of equation solution to solve your equation.
#include <iostream>
#include <cmath>
#include <cstdlib>
usingnamespace std;
int main()
{
double x, fx, fpx, x2, fx2, fpx2;
cout << "\nWhat is X when solving X²+3x-10 and 2/3x -1? ";
cout << "\nX1:";
cin >>x;
cout << "\nX2:";
cin >> x2;
do
{
fx = pow(x,2) + 3*x - 10;
fpx = 2*x + 3;
x = x - (fx/fpx);
fx2 = ((2/3)*x2) - 1;
fpx2 = 2/3;
x2 = x2 - (fx2/fpx2);
}
while (fabs(fx) > 0.001 && fabs(fx2) > 0.001 );
cout << "\nThe solution to your equation is x1 = " << x <<endl;
cout << "The solution for the 2nd is x2 = " <<x2;
return 0;
}
I do realize that this will only get me 1 root but until I can figure out how to even get that correct I just would like to know what I am doing wrong.
Write the solver. Then call it twice. First with fx1() an then with fx2().
If you don't know how to give a function (like fx1) as argument to a function (the solver),
then duplicate the solver code with different fx in each.