-
Notifications
You must be signed in to change notification settings - Fork 0
/
nonLinearSolutions.h
142 lines (118 loc) · 4.16 KB
/
nonLinearSolutions.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Universidade Federal do Rio de Janeiro
* Author: Luiz Giserman
* Class: Numeric Linear Algebra
*/
#ifndef _NON_LINEAR_SOLUTIONS__
#define _NON_LINEAR_SOLUTIONS__
#include <math.h>
#include <string>
#include <algorithm>
#include "linearEquation.h"
#include "extraFunctions.h"
#define ERROR_NO_SOLUTION 2
class Bissection : public Utilities
{
public:
Bissection(double a, double b, double tolerance);
Bissection(double a, double b);
Bissection(double tolerance);
Bissection();
double a, b, solution, tol;
bool CheckConditions();
virtual double Function(double value) {return 0.0;};
void Solve();
};
class ExOneBissection : public Bissection
{
public:
ExOneBissection() {this->CheckConditions();};
ExOneBissection(double a, double b, double tolerance) : Bissection(a, b, tolerance) {this->CheckConditions();};
ExOneBissection(double a, double b) : Bissection (a, b) {this->CheckConditions();};
ExOneBissection(double tolerance) : Bissection (tolerance) {this->CheckConditions();};
double Function(double value) {return FunctionOne(value);};
};
class ExTwoBissection : public Bissection
{
public:
ExTwoBissection() {this->CheckConditions();};
ExTwoBissection(double a, double b, double tolerance) : Bissection(a, b, tolerance) {this->CheckConditions();};
ExTwoBissection(double a, double b) : Bissection (a, b) {this->CheckConditions();};
ExTwoBissection(double tolerance) : Bissection (tolerance) {this->CheckConditions();};
double Function(double value) {return FunctionTwo(value);};
};
class Newton : public Utilities
{
public:
Newton();
Newton(double x0, double tol);
Newton (double x0, int niter, double tol);
int niter;
double x0, tol;
virtual double Function (double value) {return 0.0;};
virtual double Derivative (double value) {return 0.0;};
void Solve();
void SecantSolve();
};
class ExOneNewton : public Newton
{
public:
ExOneNewton() {};
ExOneNewton(double x0, double tol) : Newton(x0, tol) {};
ExOneNewton(double x0, int niter, double tol) : Newton (x0, niter, tol) {};
double Function(double value) {return this->FunctionOne(value);};
double Derivative(double value) {return this->DerivativeOne(value);};
};
class ExTwoNewton : public Newton
{
public:
ExTwoNewton() {};
ExTwoNewton(double x0, double tol) : Newton(x0, tol) {};
ExTwoNewton(double x0, int niter, double tol) : Newton (x0, niter, tol) {};
double Function(double value) {return this->FunctionTwo(value);};
double Derivative(double value) {return this->DerivativeTwo(value);};
};
#endif
class InverseInterpolation : public Utilities
{
public:
InverseInterpolation();
InverseInterpolation(double x1, double x2, double x3);
InverseInterpolation(double x1, double x2, double x3, int niter);
void Solve();
vector<double> xInicial;
int niter;
double tol =0.0001;
virtual double Function (double value) {return 0.0;};
double LaGrange(vector <double> x);
pair<int, double> GetElementAndIndex(vector <double> x);
};
class ExOneII : public InverseInterpolation
{
public:
ExOneII() {};
ExOneII(double x1, double x2, double x3) : InverseInterpolation(x1, x2, x3) {};
ExOneII(double x1, double x2, double x3, int niter) : InverseInterpolation(x1, x2, x3, niter) {};
double Function(double value) {return this->FunctionOne(value);};
};
class NonLinearEquations : public Utilities
{
public:
NonLinearEquations(vector <double (*)(vector <double> )> listFunctions, vector<double> firstSolution);
BasicMatrix firstSolution;
vector <double (*)(vector <double> )> listFunctions;
void GetF(BasicMatrix values, BasicMatrix &result);
double tol = 0.0001;
};
class NLE_Newton : public NonLinearEquations
{
public:
NLE_Newton(vector <double (*)(vector <double> )> listFunctions, vector<double> firstSolution): NonLinearEquations(listFunctions, firstSolution){};
void Solve();
};
class NLE_Broyden : public NonLinearEquations
{
public:
NLE_Broyden(vector <double (*)(vector <double> )> listFunctions, vector<double> firstSolution): NonLinearEquations(listFunctions, firstSolution){};
void Solve();
};