This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunction.h
143 lines (139 loc) · 6.57 KB
/
Function.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
142
143
#ifndef FUNCTION_H
#define FUNCTION_H
#pragma once
#include "stdafx.h"
class Function {
public:
std::vector <wchar_t> variables; //strictly contains variable chars i.e. it will contain x,y if f(x,y) = x^2 + y^2
std::wstring function; //contains just the rhs of the the function (using the example above, it would be 'x^2 + y^2'
Function();
~Function();
Function(std::wstring str);
Function(std::wstring vars, std::wstring funct);
Function(std::vector <wchar_t> vars, std::wstring functs);
Function(std::vector<std::wstring> vec);
void clear();
std::vector<wchar_t> varsToChars(std::wstring vars);
std::vector<wchar_t> combineVariables(std::vector<wchar_t> v1, std::vector<wchar_t> v2);
bool variablesMatch(Function a, Function b);
Function abs(Function a);
Function add(Function a, Function b);
Function subtract(Function a, Function b);
Function multiply(Function a, Function b);
Function divide(Function a, Function b);
Function inverse(Function a);
Function exponent(Function a, Function b);
Function& operator*=(Function& rhs);
Function& operator/=(Function& rhs);
Function& operator+=(Function& rhs);
Function& operator-=(Function& rhs);
Function& operator*(Function& rhs);
Function& operator/(Function& rhs);
Function& operator+(Function& rhs);
Function& operator-(Function& rhs);
friend std::wostream& operator<<(std::wostream& os, Function& rhs);
std::wstring replaceVariable(std::wstring str, wchar_t replace, std::wstring replacer);
Function compose(Function a, Function b);
double evalFunction(std::wstring str);
double evaluate(std::vector<double> vals);
double evaluate(double x);
double Function::findARoot(Function f, double lower_bound, double upper_bound);
double Function::findARoot(Function p, double lower_bound, double upper_bound, std::vector<double> vals, int pos);//for multivariate functions
std::vector<double> findRoots();
std::vector<double> findRoots(double lo, double hi);
std::vector<double> findRoots(double lo, double hi, std::vector<double> vals, int pos);//for multivariate functions
bool hasDiscontinuities(std::vector<double> testVals);//for real-valued univariate functions
bool hasDiscontinuities(Matrix testVals);//for real-valued multivariate functions
std::wstring variablesToString();
std::wstring toString();
void display();
};//================================================================
class VectorValuedFunction : public Function {
public:
std::vector<wchar_t> variables;
std::vector<Function> f;
VectorValuedFunction();
~VectorValuedFunction();
VectorValuedFunction(std::vector<wchar_t> vars, std::vector<Function> f1);
VectorValuedFunction(std::vector<Function> f1);
VectorValuedFunction::VectorValuedFunction(std::wstring f1);
void clear();
int size();
std::vector<double> evaluate(std::vector<double> vals);
std::vector<double> evaluate(double val);
std::wstring variablesToString();
std::wstring toString();
void display();
};//================================================================
class ComplexFunction : public Function {
public:
Function f;
ComplexFunction();
~ComplexFunction();
ComplexFunction(std::wstring str);
ComplexFunction(std::wstring vars, std::wstring funct);
ComplexFunction(std::vector <wchar_t> vars, std::wstring funct);
ComplexFunction(Function funct);
void clear();
ComplexFunction abs(ComplexFunction a);
ComplexFunction add(ComplexFunction a, ComplexFunction b);
ComplexFunction subtract(ComplexFunction a, ComplexFunction b);
ComplexFunction multiply(ComplexFunction a, ComplexFunction b);
ComplexFunction divide(ComplexFunction a, ComplexFunction b);
ComplexFunction exponent(ComplexFunction a, ComplexFunction b);
ComplexFunction& operator*=(ComplexFunction& rhs);
ComplexFunction& operator/=(ComplexFunction& rhs);
ComplexFunction& operator+=(ComplexFunction& rhs);
ComplexFunction& operator-=(ComplexFunction& rhs);
ComplexFunction& operator*(ComplexFunction& rhs);
ComplexFunction& operator/(ComplexFunction& rhs);
ComplexFunction& operator+(ComplexFunction& rhs);
ComplexFunction& operator-(ComplexFunction& rhs);
friend std::wostream& operator<<(std::wostream& os, ComplexFunction& rhs);
ComplexNumber evalComplexFunction(std::wstring str);
ComplexNumber evaluateComplex(std::vector<ComplexNumber> vals);
ComplexNumber evaluateComplex(ComplexNumber z);
bool hasDiscontinuities(std::vector<ComplexNumber> testVals);//for complex-valued univariate functions
bool hasDiscontinuities(ComplexMatrix testVals);//for complex-valued multivariate functions
std::wstring variablesToString();
std::wstring toString();
void display();
};//================================================================
class ParametricFunction {
//a parametric function is a function comprised of many functions all unified with a set of parameters
public:
std::vector <wchar_t> variables; //strictly contains variable chars i.e. it will contain x,y if F(x,y) = x^2i + y^2j
std::wstring function; //contains just the rhs of the the function (using the example above, it would be 'x^2i + y^2j'
ParametricFunction();
~ParametricFunction();
ParametricFunction(std::wstring str);
ParametricFunction(std::vector<wchar_t> params, std::wstring functs);
ParametricFunction(std::wstring vars, std::wstring funct);
std::wstring variablesToString();
std::wstring toString();
void display();
};//========================================================
//Helper functions for string parsing:
int findFunction(std::wstring in);
bool hasFunction(std::wstring in);
bool hasOperator(std::wstring in);
int findComplexNumber(std::wstring str);
int findNearestDouble(std::wstring str);
std::wstring getNearestComplexNumber(std::wstring str);
std::wstring removeComplexNumbers(std::wstring str);
std::wstring removeDoubles(std::wstring str);
int countComplexNumbers(std::wstring str);
int countOperators(std::wstring str);
bool hasOperatorNotComplexNumber(std::wstring in);
int findOperator(std::wstring in);
std::wstring convertDoubleToComplex(std::wstring funct);
bool isOperableExpressionComplex(std::wstring tempstr);
bool isOperableExpression(std::wstring tempstr);
std::wstring processInnerTermsComplex(std::wstring str);
std::wstring processInnerTerms(std::wstring str);
std::wstring processTwoTermOperationComplex(std::wstring funct, std::wstring tempstr);
std::wstring processTwoTermOperation(std::wstring funct, std::wstring tempstr);
ComplexNumber calculateArithmeticComplex(std::wstring funct);
double calculateArithmetic(std::wstring funct);
bool testForFunctions(std::wstring in);
#endif