Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "functioncalculater.h"
- #include <stdlib.h>
- FunctionCalculater::FunctionCalculater()
- {
- }
- //method Monte-Carlo
- double FunctionCalculater::integrate(double (*calculate)(double), double from, double to)
- {
- double resultSum = 0;
- for(double tmp = from; tmp<to; tmp+=gap)
- {
- double base = ( tmp+gap<=to)?(gap):(to-tmp);
- resultSum += base * calculate(tmp);
- }
- return resultSum;
- }
- double *FunctionCalculater::calculateInInterval(double (*calculate)(double), double from, double to)
- {
- int count = (int) (( to-from)/gap);
- double *result = new double[ (int) (( to-from)/gap) ];
- return result;
- }
- comp FunctionCalculater::cintegrate(comp (*calculate)(comp), const comp& from , const comp& to)
- {
- comp resultSum;
- for(comp tmp = from; std::abs(tmp) < std::abs(to); tmp+=gap)
- {
- comp base = ( std::abs(tmp+gap)<=std::abs(to))?(gap):(to-tmp);
- resultSum += base * ( calculate(tmp) );
- cout << resultSum << endl;
- }
- return resultSum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement