- added bisektion. for "nlgs"

This commit is contained in:
Patrice Matz 2017-11-03 22:39:12 +01:00
parent e1360d5f36
commit a65120eb3f
3 changed files with 56 additions and 0 deletions

View File

@ -5,6 +5,7 @@ using namespace std;
void cylinder(); void cylinder();
void lgs(); void lgs();
void nlgs();
int main() int main()
{ {
@ -14,6 +15,7 @@ int main()
cout << "Was wollen Sie tun ?" << endl; cout << "Was wollen Sie tun ?" << endl;
cout << "1 Berechungen an einem Zylinder" << endl; cout << "1 Berechungen an einem Zylinder" << endl;
cout << "2 LGS loesen" << endl; cout << "2 LGS loesen" << endl;
cout << "3 n.LGS loesen" << endl;
cout << "e Beenden" << endl; cout << "e Beenden" << endl;
@ -22,6 +24,7 @@ int main()
{ {
case '1': cylinder(); break; case '1': cylinder(); break;
case '2': lgs(); break; case '2': lgs(); break;
case '3': nlgs(); break;
default: cout << "Okay, bye" << endl; break; default: cout << "Okay, bye" << endl; break;
} }
@ -44,3 +47,7 @@ void lgs()
cout << lgs.cramer(); cout << lgs.cramer();
cout << endl; cout << endl;
} }
void nlgs()
{
}

34
SCE/SCE/nlgs.cpp Normal file
View File

@ -0,0 +1,34 @@
#include "nlgs.h"
#include "math.h"
#include <iostream>
using namespace std;
long double nlgs::function(long double x)
{
return (pow(x, 4) - x - 10);
}
long double nlgs::round(long double x, int acc)
{
x = x * pow(10, acc);
int temp = x;
x = temp;
x = x / pow(10, acc);
return x;
}
float nlgs::bisektion(long double A, long double B , int limit, int acc)
{
long double a = A;
long double b = B;
long double c;
for (int i = limit; i--;)
{
c = (a + b) / 2;
c = round(c, acc);
if (function(a)*function(c) > 0) { a = c; }
if (function(c)*function(b) > 0) { b = c; }
}
}

15
SCE/SCE/nlgs.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
class nlgs
{
private:
long double function(long double);
long double round(long double, int);
public:
float bisektion(long double, long double, int, int ); //a, b, number of iterations, accuracy
float fixedpoint();
float newton();
float secant();
nlgs(){};
~nlgs(){};
};