# mXparser - user defined functions applied to Fundamental theorem of calculus

Fundamental Theorem of Calculus is a kind of a link between two most important calculus concepts: derivative and integral.

## Fundamental Theorem of Calculus - formal statement

For continuous real-valued function  defined on closed interval  let  be the function given by



The  is uniformly continuous on , differentiable on the open interval , and



## Fundamental Theorem of Calculus - mXparser test

import org.mariuszgromada.math.mxparser.*;
...
/* Function */
Function f = new Function("f(x) = sin(x)");

/* Antiderivative */
Function F = new Function("F(x) = int(f(t), t, 0, x)", f);

/* function = derivative ( antiderivative ) */
Argument x = new Argument("x = pi");
Expression e = new Expression("f(x) - der(F(x), x)", x, f, F);
mXparser.consolePrintln("Res : " + e.getExpressionString() + " = " + e.calculate());
mXparser.consolePrintln("Computing time = " + e.getComputingTime() + " s.");

Res : f(x) - der(F(x), x) = 6.237833817291525E-8
Computing time = 0.411 s.


Best regards,

## 12 thoughts on “mXparser - user defined functions applied to Fundamental theorem of calculus”

1. I’m not that much of a online reader to be honest but your sites really nice, keep
to come back later on. All the best

Thanx a lot 🙂 Best regards - Mariusz

2. Carlo says:

Hello, i feel that i saw you visited my website so i got here to go back the
prefer?.I'm trying to find issues to enhance my site!I assume its ok to use a few of your ideas!!

3. Nagireddy.Bhavanam says:

Can you give max length of formula string

Formula string is a String type - if limitation exist this is related to String class. Additionally internal iterators are "int" types, so forula length is definitely limited by max int 🙂

4. Lukas says:

I need your help i use mxparser for a curve discussion programm, I use the 2nd derivation and sometimes it is Nan, although it shouldn't be. Any idea to fix it?
Examples:
Expression e2 = new Expression("solve( der( der(" + fkt + ", x), x), x, " + z + "," + (z + 1) + ")", x);
Expression e2ex = new Expression("solve( der( der(" + fkt + ", x), x), x, " + i + "," + (i + 1) + ")", x);

Can you give the whole code? What is fkt, z, x, i?

5. Lukas says:

ty for your fast response, here is the code:
/*
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package projekt.syp;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

/**
* @author laura
*/
public class Extrempunktrechner {

public static double eps = 0.0001;

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Map<String, Set> m = calcExtrem("1/16*(x^4-24*x^2+128)", "-5", "5");
for (String s : m.keySet()) {
System.out.println(s + "->" + m.get(s));
}
}

public static Map<String, Set> calcExtrem(String fkt, String minlimit, String maxLimit) {
Set hSet = new TreeSet(); //Set für Hochpunkte
Set tSet = new TreeSet(); //Set für Tiefpunkte
Set sSet = new TreeSet(); //Set für Sattelpunkte
Map<String, Set> extrem = new TreeMap(); //Map für alle Punkte
extrem.put("Hochpunkt", hSet);
extrem.put("Tiefpunkt", tSet);
extrem.put("Sattelpunkt", sSet);
Double min, max;
try {
min = Double.parseDouble(minlimit); //min und max in Double umwandeln
max = Double.parseDouble(maxLimit);
if (max < min) {
throw new NumberFormatException();
}
} catch (NumberFormatException nfe) {
alert.setContentText("Min oder Max war keine Zahl!!");
return null;
}
for (double i = min; i <= max; i++) { //alle Werte im Intervall auf Extrempunkte überprüfen
Argument x = new Argument("x");
Expression e = new Expression("solve(der(" + fkt + ", x), x, " + i + "," + (i + 1) + ")", x);
double z = e.calculate(); //Wert der ersten Ableitung ausrechnen
Expression e2 = new Expression("solve( der( der(" + fkt + ", x), x), x, " + z + "," + (z + 1) + ")", x); //Zweite Ableitung
Expression e2ex = new Expression("solve( der( der(" + fkt + ", x), x), x, " + i + "," + (i + 1) + ")", x); //Falls irgendwie z Nan ist, jedoch die mit i ein Ergebnis rauskommen würde
double erg = e2.calculate(), ergx = e2ex.calculate(); //Ergebnis kalkulieren
if (erg < 0 || ergx 0 || ergx > 0) {
}
}
for (String s : extrem.keySet()) {
Iterator iterator = extrem.get(s).iterator(); //Iterator erzeugen zwecks entfernung von NaN werten
while (iterator.hasNext()) {
Double d = iterator.next();
if (Double.toString(d).equals(Double.toString(Double.NaN))) {
iterator.remove();
}
}
}

return extrem;
}

}

Ok - will look on that.

The problem is here.

You are trying to run "solve(der(1/16*(x^4-24*x^2+128), x), x, -5.0,-4.0)", but

Function derf = new Function("derf(x0) = der(1/16*(x^4-24*x^2+128), x, x0)");
mXparser.consolePrintln(derf.calculate(-5));
mXparser.consolePrintln(derf.calculate(-4));