Dynamic Y Bounds
This commit is contained in:
27
main.cpp
27
main.cpp
@@ -2,6 +2,9 @@
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
|
||||
float lowerX = 0;
|
||||
float upperX = 20;
|
||||
|
||||
double randomFloat()
|
||||
{
|
||||
return (double)(rand()) / (double)(RAND_MAX);
|
||||
@@ -68,6 +71,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
double function(double x) {
|
||||
return pow(x,4)-4*pow(x,3)+18*pow(x,2)-12*x-69;
|
||||
}
|
||||
@@ -83,12 +88,32 @@ bool getIsInside(Point p) {
|
||||
double getRealIntegral(LinearBounds bounds) {
|
||||
return indefiniteIntegral(bounds.get_upper())- indefiniteIntegral(bounds.get_lower());
|
||||
}
|
||||
float getUpperLimit() {
|
||||
float upperLimit = 0;
|
||||
for(float i = lowerX; i< upperX; i+= 0.025) {
|
||||
if(function((double)i) > upperLimit) {
|
||||
upperLimit = (float) (function(i) * 1.025);
|
||||
}
|
||||
}
|
||||
return upperLimit;
|
||||
}
|
||||
float getLowerLimit() {
|
||||
float lowerLimit = 0;
|
||||
for(float i = lowerX; i< upperX; i+= 0.025F) {
|
||||
if(function(i) < lowerLimit) {
|
||||
lowerLimit = (float) (function(i) * 1.025);
|
||||
}
|
||||
}
|
||||
return lowerLimit;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
double pointsInside = 0;
|
||||
double samples = 10000000;
|
||||
Bounds bounds = Bounds(LinearBounds(0, 20), LinearBounds(-100, 150000));
|
||||
Bounds bounds = Bounds(LinearBounds(lowerX, upperX), LinearBounds(getLowerLimit(), getUpperLimit()));
|
||||
Point toTestPoint;
|
||||
for (int i = 0; i< samples; i++) {
|
||||
toTestPoint = bounds.getRandomPoint();
|
||||
|
||||
Reference in New Issue
Block a user