Page MenuHomec4science

main.cpp
No OneTemporary

File Metadata

Created
Wed, Jun 5, 15:09

main.cpp

#include <iostream>
#include <math.h>
#include "IntegralSolver1D.hpp"
#include "IntegralSolver2D.hpp"
#include "IntegrationSolver.hpp"
#include "Function.hpp"
#include "Domain.hpp"
#include "Method.hpp"
#include <iostream>
using namespace std;
#include <vector>
/* USER DEFINED FUNCTION
*
* Input : vector of double x
* Output : double
* Function is defined as f : Rn -> R where n is at least 1
*
*/
double myFunction1D(vector<double> x) {
return x[0] * x[0];
}
double myFunction2D(vector<double> x) {
return x[0]*x[1];
}
int main(int argc, char *argv[]) {
////////// 2D test //////////
// Creation of the function pointer
double (*functionPointer2D)(vector<double>) = &myFunction2D;
// Creation of the function to be integrated
Function function2D(functionPointer2D);
// Boundaries matrix
vector<vector<double>> boundaries2D;
vector<double> dim1;
vector<double> dim2;
dim1.push_back(0);
dim1.push_back(5);
dim2.push_back(0);
dim2.push_back(5);
boundaries2D.push_back(dim1);
boundaries2D.push_back(dim2);
// Subdivision vector
vector<int> subdivision;
subdivision.push_back(100);
subdivision.push_back(100);
// Creation of the domain of integration, method
Domain domain2D(boundaries2D, subdivision);
Method method2D("Midpoint");
// Creation of the solver
IntegrationSolver Integration2D(function2D, domain2D, method2D);
// Asking to compute the result
double result2D = Integration2D.GetResult();
std::cout << "Result is : " << result2D << " using " << method2D.name << "'s method" << std::endl;
////////// 1D test //////////
// Creation of the pointer to the function to integrate
double (*functionPointer1D)(vector<double>);
functionPointer1D = &myFunction1D;
// Object creation
Function function1D(functionPointer1D);
Domain domain1D(0, 5, 100);
Method method1D("Trapz");
IntegrationSolver Integration1 = IntegrationSolver(function1D, domain1D, method1D);
// Asking to compute the result
double result1D = Integration1.Compute();
std::cout << "Result is : " << result1D << " using " << method1D.name << "'s method" << std::endl;
domain1D.essai("ww");
return 0;
}

Event Timeline