• Increase font size
  • Default font size
  • Decrease font size

numerical integration class

The Fundamental Theorem of Calculus gives us an exact formula for computing abf(x) dx, provided we can find an antiderivative for f.

This method of evaluating definite integrals is called the analytic method. However, there are times when this is difficult or impossible. In these cases, it is usually good enough to find an approximate, or numerical solution, and there are some very straighforward ways to do this. [1]

Here you can find a processing project that contains "cIntegrate" which calculates numeric value of the integral abf(x) dx based on "Left Riemann Sums". The cIntegrate class has following interface:

- cIntegrate(float _a, float _b) - constructor which specifies left (_a) and right (_b) border of the calculated interval.
public float solve(intMethodIntegrate methodIntegrateImpl) - method accepts name of the object from class that contains method to be integrated. This class has to implement interface intMethodIntegratel, which allows to pass the method about to integrate as callback method.

note.: important parameter for Riemann Sums algorithm is number of subintervals the <a,b> interval is divided into. By default constructor sets variable "n = 100;" , however the variable is publicaly accessible.

note1: results of the class were compaired to results from http://www.plu.edu/~heathdj/java/calc2/Riemann.html.

Example:

 //create class that implements interface intMethodIntegrate
class cToIntegrate1 implements intMethodIntegrate {
 public float methodToIntegrate(float x) {
 return x * x;
 }
}
 
//Instanciate the class
 cToIntegrate1 f1 = new cToIntegrate1();
 
 //Create object that will solve integral in the interval <1, 4>
 cIntegrate integrate = new cIntegrate(1, 4);
 
 //Setup num of intervals Riemann algorithm uses
 integrate.n = 2;
 
 //calculate integral
 float  res = integrate.solve(f1);
 

 

Add comment

No bad words.


Security code
Refresh


New articles

Contact programming-other
Read More 100 Hits
Rasco Resizer - documentation programming-other
Read More 93 Hits
Programming partners programming-other
Read More 205 Hits
Read More 436 Hits

Most read content

New articles

Contact programming-other
Read More 100 Hits
Rasco Resizer - documentation programming-other
Read More 93 Hits
Programming partners programming-other
Read More 205 Hits
Read More 436 Hits
Design by i-cons.ch / etosha-namibia.ch