Gin
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Integrator Class Reference

Numerical integration using the trapezoidal rule for discrete data points. More...

#include <gin_integrator.h>

Public Member Functions

 Integrator ()=default
 
void clear ()
 
double getIntegral ()
 
void addPoint (double x, double y)
 
void addPoint (Point< double > point)
 
void addPoints (juce::Array< Point< double > > points)
 

Detailed Description

Numerical integration using the trapezoidal rule for discrete data points.

Integrator calculates the definite integral of a function represented by a series of (x, y) data points using the trapezoidal rule. This is useful for computing areas under curves, cumulative sums, or any integration task where you have discrete data points rather than a continuous function.

The trapezoidal rule approximates the area between consecutive points as trapezoids, providing good accuracy for reasonably smooth data.

Key Features:

Important: Points must be added in increasing x order for correct results.

Usage:

// Add data points in increasing x order
integrator.addPoint(0.0, 0.0);
integrator.addPoint(1.0, 2.5);
integrator.addPoint(2.0, 4.0);
integrator.addPoint(3.0, 3.5);
integrator.addPoint(4.0, 1.0);
// Get the accumulated integral
double area = integrator.getIntegral();
// Clear and start over
integrator.clear();
Numerical integration using the trapezoidal rule for discrete data points.
Definition gin_integrator.h:54
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
See also
Spline, LeastSquaresRegression

Constructor & Destructor Documentation

◆ Integrator()

Integrator::Integrator ( )
default

Member Function Documentation

◆ clear()

void Integrator::clear ( )

◆ getIntegral()

double Integrator::getIntegral ( )

◆ addPoint() [1/2]

void Integrator::addPoint ( double  x,
double  y 
)

◆ addPoint() [2/2]

void Integrator::addPoint ( Point< double point)

◆ addPoints()

void Integrator::addPoints ( juce::Array< Point< double > >  points)

The documentation for this class was generated from the following file: