mirror of https://github.com/Askill/AP-SCE.git
parent
6315877d26
commit
f8033ef4ac
|
|
@ -0,0 +1,74 @@
|
||||||
|
#include "DIFF.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
DIFF::DIFF()
|
||||||
|
{
|
||||||
|
y1values.resize(yvalues.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DIFF::~DIFF()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<long double> DIFF::diff()
|
||||||
|
{
|
||||||
|
vector<long double> diff = yvalues;
|
||||||
|
vector<long double> xdiff (diff.size()-1);
|
||||||
|
for(unsigned int i = 0; i < xdiff.size(); i++)
|
||||||
|
{
|
||||||
|
xdiff.at(i) = diff.at(i+1) - diff.at(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return xdiff;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<long double> DIFF::forward_diff()
|
||||||
|
{
|
||||||
|
for(unsigned int i=0; i < xvalues.size()-1; i++)
|
||||||
|
{
|
||||||
|
y1values.at(i) = (yvalues.at(i + 1) - yvalues.at(i)) / (xvalues.at(i + 1) - xvalues.at(i));
|
||||||
|
}
|
||||||
|
y1values.at(25) = 0;
|
||||||
|
return y1values;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<long double> DIFF::backward_diff()
|
||||||
|
{
|
||||||
|
|
||||||
|
for (unsigned int i = 1; i < xvalues.size(); i++)
|
||||||
|
{
|
||||||
|
y1values.at(i) = (yvalues.at(i) - yvalues.at(i-1)) / (xvalues.at(i) - xvalues.at(i-1));
|
||||||
|
}
|
||||||
|
y1values.at(0) = 0;
|
||||||
|
return y1values;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<long double> DIFF::backward_diff(vector<long double> y)
|
||||||
|
{
|
||||||
|
vector<long double> temp;
|
||||||
|
temp.resize(y.size());
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < y.size() - 1; i++)
|
||||||
|
{
|
||||||
|
temp.at(i) = (y.at(i + 1) - y.at(i)) / (xvalues.at(i + 1) - xvalues.at(i));
|
||||||
|
}
|
||||||
|
temp.at(25) = 0;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
vector<long double> DIFF::forward_diff(vector<long double> y)
|
||||||
|
{
|
||||||
|
vector<long double> temp;
|
||||||
|
temp.resize(y.size());
|
||||||
|
|
||||||
|
for (unsigned int i = 1; i < y.size(); i++)
|
||||||
|
{
|
||||||
|
temp.at(i) = (y.at(i) - y.at(i - 1)) / (xvalues.at(i) - xvalues.at(i - 1));
|
||||||
|
}
|
||||||
|
temp.at(0) = 0;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class DIFF
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
vector<long double> xvalues = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250};
|
||||||
|
vector<long double> yvalues = {0, 2926, 10170, 21486, 33835, 45251, 55634, 65038, 73461, 80905, 87368, 92852, 97355, 100878, 103422, 104986, 106193, 110246, 119626, 136106, 162095, 199506, 238775, 277065, 314375, 350704};
|
||||||
|
vector<long double> y1values; //y-values of 1st derivative
|
||||||
|
vector<long double> y2values; //y-values of 2nd derivative
|
||||||
|
vector<long double> diff();
|
||||||
|
vector<long double> forward_diff();
|
||||||
|
vector<long double> backward_diff();
|
||||||
|
|
||||||
|
vector<long double> forward_diff(vector<long double>);
|
||||||
|
vector<long double> backward_diff(vector<long double>);
|
||||||
|
|
||||||
|
|
||||||
|
DIFF();
|
||||||
|
~DIFF();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -2,11 +2,31 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "lgs.h"
|
#include "lgs.h"
|
||||||
#include "nlgs.h"
|
#include "nlgs.h"
|
||||||
|
#include "DIFF.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void cylinder();
|
void cylinder();
|
||||||
void lgs();
|
void lgs();
|
||||||
void nlgs();
|
void nlgs();
|
||||||
|
void diff();
|
||||||
|
void print_array(long double* a, int size)
|
||||||
|
{
|
||||||
|
cout << endl;
|
||||||
|
for(int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
cout << a[i] << "\t";
|
||||||
|
}
|
||||||
|
cout << endl << endl;
|
||||||
|
}
|
||||||
|
void print_array(long double* a, long double* b, int size)
|
||||||
|
{
|
||||||
|
cout << endl;
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
cout << a[i] << "," << b[i] << endl;
|
||||||
|
}
|
||||||
|
cout << endl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
@ -17,6 +37,7 @@ int main()
|
||||||
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 << "3 n.LGS loesen" << endl;
|
||||||
|
cout << "5 numerische differentation" << endl;
|
||||||
|
|
||||||
cout << "e Beenden" << endl;
|
cout << "e Beenden" << endl;
|
||||||
|
|
||||||
|
|
@ -26,6 +47,7 @@ int main()
|
||||||
case '1': cylinder(); break;
|
case '1': cylinder(); break;
|
||||||
case '2': lgs(); break;
|
case '2': lgs(); break;
|
||||||
case '3': nlgs(); break;
|
case '3': nlgs(); break;
|
||||||
|
case '5': diff(); break;
|
||||||
|
|
||||||
default: cout << "Okay, bye" << endl; break;
|
default: cout << "Okay, bye" << endl; break;
|
||||||
}
|
}
|
||||||
|
|
@ -52,5 +74,18 @@ void lgs()
|
||||||
|
|
||||||
void nlgs()
|
void nlgs()
|
||||||
{
|
{
|
||||||
|
NLGS nlgs;
|
||||||
|
cout << endl << "Bisektion: " << nlgs.bisektion(1,4,100) << endl;
|
||||||
|
cout << "Fixpunkt: " << nlgs.fixedpoint(1,100) << endl;
|
||||||
|
cout << "Newton: " <<nlgs.newton(1,100) << endl;
|
||||||
|
cout << "skantenverfahren fehlt" << endl << endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void diff() {
|
||||||
|
DIFF diff;
|
||||||
|
|
||||||
|
print_array(diff.xvalues.data(), diff.forward_diff().data(), diff.xvalues.size());
|
||||||
|
print_array(diff.xvalues.data(), diff.backward_diff(diff.forward_diff()).data(), diff.xvalues.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,24 +4,24 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
long double nlgs::function(long double x)
|
long double NLGS::function(long double x)
|
||||||
{
|
{
|
||||||
return (pow(x, 4) - x - 10);
|
return (pow(x, 4) - x - 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
long double nlgs::function_fixedpoint(long double x)
|
long double NLGS::function_fixedpoint(long double x)
|
||||||
{
|
{
|
||||||
return pow(x+10, 1/4);
|
return pow(x+10, 1/4);
|
||||||
}
|
}
|
||||||
|
|
||||||
long double nlgs::function_derived(long double x)
|
long double NLGS::function_derived(long double x)
|
||||||
{
|
{
|
||||||
return 4 * pow(x, 3) - 1;
|
return 4 * pow(x, 3) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long double nlgs::bisektion(long double A, long double B , int limit)
|
long double NLGS::bisektion(long double A, long double B , int limit)
|
||||||
{
|
{
|
||||||
long double a = A, b = B, c;
|
long double a = A, b = B, c;
|
||||||
for (int i = limit; i--;)
|
for (int i = limit; i--;)
|
||||||
|
|
@ -33,7 +33,7 @@ long double nlgs::bisektion(long double A, long double B , int limit)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
long double nlgs::fixedpoint(long double start, int limit)
|
long double NLGS::fixedpoint(long double start, int limit)
|
||||||
{
|
{
|
||||||
long double x = start;
|
long double x = start;
|
||||||
for(int i = limit ; i-- ;)
|
for(int i = limit ; i-- ;)
|
||||||
|
|
@ -43,7 +43,7 @@ long double nlgs::fixedpoint(long double start, int limit)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
long double nlgs::newton(long double start, int limit)
|
long double NLGS::newton(long double start, int limit)
|
||||||
{
|
{
|
||||||
long double x = start;
|
long double x = start;
|
||||||
for (int i = limit; i--;)
|
for (int i = limit; i--;)
|
||||||
|
|
@ -53,7 +53,7 @@ long double nlgs::newton(long double start, int limit)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
long double nlgs::secant(long double A, long double B, int limit)
|
long double NLGS::secant(long double A, long double B, int limit)
|
||||||
{
|
{
|
||||||
long double a = A, b = B;
|
long double a = A, b = B;
|
||||||
for (int i = limit; i--;)
|
for (int i = limit; i--;)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
class nlgs
|
class NLGS
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
long double function(long double);
|
long double function(long double);
|
||||||
|
|
@ -11,7 +11,7 @@ public:
|
||||||
long double fixedpoint(long double, int); //start, number of iterations
|
long double fixedpoint(long double, int); //start, number of iterations
|
||||||
long double newton(long double, int); //start, number of iterations
|
long double newton(long double, int); //start, number of iterations
|
||||||
long double secant(long double, long double, int); //a, b, number of iterations
|
long double secant(long double, long double, int); //a, b, number of iterations
|
||||||
nlgs(){};
|
NLGS(){};
|
||||||
~nlgs(){};
|
~NLGS(){};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue