Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88822273
main.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Oct 20, 20:48
Size
2 KB
Mime Type
text/x-c
Expires
Tue, Oct 22, 20:48 (2 d)
Engine
blob
Format
Raw Data
Handle
21814676
Attached To
R7917 Guggisberg-Liardon - Numerical integration
main.cpp
View Options
#include <iostream>
#include <math.h>
#include "IntegralSolver1D.hpp"
#include "IntegralSolver2D.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
// DomainCartesian domain2D(boundaries2D, subdivision);
// Method method2D("Midpoint");
//
// // Creation of the solver
// IntegralSolver2D 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
);
DomainCartesian
domain1D
(
0
,
5
,
100
);
Method
method1D
(
"Trapz"
);
IntegralSolver1D
Integration1
(
function1D
,
domain1D
,
method1D
);
// // Asking to compute the result
// double result1D = Integration1.GetResult();
// std::cout << "Result is : " << result1D << " using " << method1D.name << "'s method" << std::endl;
return
0
;
}
Event Timeline
Log In to Comment