-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Closed
Labels
enhancementNew feature or requestNew feature or requeststaleAuthor has not responded to the comments for over 2 weeksAuthor has not responded to the comments for over 2 weeks
Description
Add integral functionality
Detailed Description
Add a function fnInt(...) that returns the approximate integral of some function on [a, b] (the function must be continuous on [a, b]). uses Riemann sum except with trapezoids rather than rectangles (for greater accuracy).
Context
Integrals have a lot of uses in many fields of mathematics.
Possible Implementation
template<typename R, typename I> //R and I should be either float or double. R is return type, I is input type
R fnInt(I a, I b, R (f)(I), I subdivisions) {
R result;
I dx = (b - a)/subdivisions;
for(; a < b; a += dx) {
result += 0.5dx*(f(a) + f(a + dx)); //area of trapezoid
}
return result;
}
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requeststaleAuthor has not responded to the comments for over 2 weeksAuthor has not responded to the comments for over 2 weeks