// Aufgabe 23-2b.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//

#include "stdafx.h"
#include "std-rene-schwarz.h"
#include "math.h"


int _tmain(int argc, _TCHAR* argv[])
{
	cout << rsheader << endl;

	float a, b, n, x, nst, puffer;


	cout << "Newtonsches Iterationsverfahren\n================================\nAufgabe 23-2b\n\n" << endl;


	cout << "f(x) = x^n + 2*x^(n-1) - 2*x - 1\n\n" << endl;
	cout << "Bitte geben Sie nun die folgenden Parameter ein:" << endl;
	cout << "n: ";
	cin >> n;
	cout << "\nF" << ue << "r das Newtonsche Iterationsverfahren sind verschiedene Vorgaben notwendig." << endl;
	cout << "Intervallgrenze a: ";
	cin >> a;
	cout << "Intervallgrenze b: ";
	cin >> b;
	cout << "Startwert x: ";
	cin >> x;

	while( !((x > a && x < b) || (x > b && x < a)) )
	{
		cout << "\nIhr Startwert x liegt nicht im angegebenen Intervall." << endl;
		cout << "Startwert x: ";
		cin >> x;
	}

	nst = x;

	if(a < b)
	{
		puffer = a - 1;
	}
	else
	{
		puffer = b - 1;
	}

	while( (long int)(puffer*100000) != (long int)(nst*100000) )
	{
		puffer = nst;
		nst = nst - ((pow(nst, n) + 2 * pow(nst, n-1) - 2*nst - 1) / (n * pow(nst, n-1) + 2 * (n-1) * pow(nst, n-2) - 2));
		cout << "Iterationsschritt: x0 = " << (float)nst << endl;
	}

	cout << "Die Nullstelle liegt ann" << ae << "hernd bei x0 = " << (float)nst << endl;

	system("PAUSE");
	return 0;
}
