Skip to content

[FEATURE] add integral function #1469

@Bro0x00

Description

@Bro0x00

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.5
dx*(f(a) + f(a + dx)); //area of trapezoid
}
return result;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requeststaleAuthor has not responded to the comments for over 2 weeks

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions