Newton-Rapson Method

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.

fx1(x) = x2 + 3x -10
fx2(x) = 2/3x -1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  
#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace 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.

Thanks
Why do you try to solve two totally unrelated equations simultaneously?
That is the assingment.
I don't think so.

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.
Topic archived. No new replies allowed.