Gin
Loading...
Searching...
No Matches
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:

  • Simple and efficient numerical integration
  • Works with discrete data points
  • Accumulates integral as points are added
  • No memory overhead (streaming calculation)

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

Usage:

Integrator integrator;
// 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();
double getIntegral()
Integrator()=default
void addPoint(double x, double y)
void clear()
See also
Spline, LeastSquaresRegression

Constructor & Destructor Documentation

◆ Integrator()

Integrator::Integrator ( )
default

Referenced by addPoints().

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)

References Integrator().


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