-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegral.cpp
More file actions
40 lines (30 loc) · 889 Bytes
/
Copy pathintegral.cpp
File metadata and controls
40 lines (30 loc) · 889 Bytes
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
/********************************
* Name: Julian Moskovits
* Description: The "integrate" function takes a function, and 2 doubles as parameters and integrates the function between those points.
********************************/
#include <iostream>
using namespace std;
typedef double (*FUNC) (double);
double integrate(FUNC f, double a, double b){
double sum = 0;
for (double i = a; i < b; i += 0.0001){
sum += (0.0001 * f(i));
}
return sum;
}
double line(double x){
return x;
}
double square(double x){
return x * x;
}
double cube(double x){
return x * x * x;
}
int main()
{
cout << "The integral of f(x) = x between 1 and 5 is: " << integrate(line, 1, 5) << endl;
cout << "The integral of f(x) = x^2 between 1 and 5 is: " << integrate(square, 1, 5) << endl;
cout << "The integral of f(x) = x^3 bewtween 1 and 5 is: " << integrate(cube, 1, 5) << endl;
return 0;
}