Derivatives & Integrals

TO SUPPORT MY WORK, ORDER A COMMERCIAL LICENSE
THANK YOU!

Tutorial Math Collection API spec Download

Below is the code for JAVA, the code for C# is almost identical.

Case 1: General derivative – at given point

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("cos(1) - der(sin(x), x, 1)");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] Res: cos(1) - der(sin(x), x, 1) = 8.588628E-10

Case 2: General derivative – point given by argument value

import org.mariuszgromada.math.mxparser.*;
...
Argument x = new Argument("x = 1");
Expression e = new Expression("cos(x) - der(sin(x), x)", x);
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] Res: cos(x) - der(sin(x), x) = 8.588628E-10

Case 3: Left / right derivative – at given point

import org.mariuszgromada.math.mxparser.*;
...
Expression e1 = new Expression("der-(abs(x), x, 0)");
Expression e2 = new Expression("der+(abs(x), x, 0)");

mXparser.consolePrintln("Res 1: " + e1.getExpressionString() + " = " + e1.calculate());
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate());
[mXparser-v.5.0.0] Res 1: der-(abs(x), x, 0) = -1.0
[mXparser-v.5.0.0] Res 2: der+(abs(x), x, 0) = 1.0

Case 4: Left / right derivative – point given by argument value

import org.mariuszgromada.math.mxparser.*;
...
Argument x = new Argument("x = 0");
Expression e1 = new Expression("der-(abs(x), x)", x);
Expression e2 = new Expression("der+(abs(x), x)", x);
         
mXparser.consolePrintln("Res 1: " + e1.getExpressionString() + " = " + e1.calculate());
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate());
[mXparser-v.5.0.0] Res 1: der-(abs(x), x) = -1.0
[mXparser-v.5.0.0] Res 2: der+(abs(x), x) = 1.0

Case 5: Derivative from more complex function – at given point

import org.mariuszgromada.math.mxparser.*;
...
/* Derivative from Taylor series approximation of sin(x)*/
Expression e1 = new Expression("cos(1) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x, 1)");
mXparser.consolePrintln("Res 1: " + e1.getExpressionString() + " = " + e1.calculate());

Expression e2 = new Expression("cos(2) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x, 2)");
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate());

Expression e3 = new Expression("cos(3) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x, 3)");
mXparser.consolePrintln("Res 3: " + e3.getExpressionString() + " = " + e3.calculate());
[mXparser-v.5.0.0] Res 1: cos(1) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x, 1) = 8.588628E-10
[mXparser-v.5.0.0] Res 2: cos(2) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x, 2) = -2.6459193E-9
[mXparser-v.5.0.0] Res 3: cos(3) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x, 3) = -1.5994834E-9

Case 6: Derivative from more complex function – point given by argument value

import org.mariuszgromada.math.mxparser.*;
...
Argument x = new Argument("x = 1");

/* Derivative from Taylor series approximation of sin(x)*/
Expression e = new Expression("cos(x) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x)", x);
mXparser.consolePrintln("Res 1: " + e.getExpressionString() + " = " + e.calculate());

x.setArgumentValue(2);
mXparser.consolePrintln("Res 2: " + e.getExpressionString() + " = " + e.calculate());

x.setArgumentValue(3);
mXparser.consolePrintln("Res 3: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] Res 1: cos(x) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x) = 8.588628E-10
[mXparser-v.5.0.0] Res 2: cos(x) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x) = -2.6459193E-9
[mXparser-v.5.0.0] Res 3: cos(x) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x) = -1.5994834E-9

Case 7: Integrals – calculating pi by integration sqrt(1-x^2)

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2 * int( sqrt(1-x^2), x, -1, 1 )");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] Res: 2 * int( sqrt(1-x^2), x, -1, 1 ) = 3.1415920928388927
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.0.6

Nuget – .NET CLI

dotnet add package MathParser.org-mXparser --version 5.0.6

Nuget – Package Reference

<PackageReference Include="MathParser.org-mXparser" Version="5.0.6"/>

Maven – Dependency

<dependency>
<groupid>
org.mariuszgromada.math</groupid>
<artifactid>
MathParser.org-mXparser</artifactid>
<version>
5.0.6</version>
</dependency>

Maven – Gradle

implementation 'org.mariuszgromada.math:MathParser.org-mXparser:5.0.6'

Maven – Gradle (Kotlin)

implementation("org.mariuszgromada.math:MathParser.org-mXparser:5.0.6")

GitHub

git clone https://github.com/mariuszgromada/MathParser.org-mXparser

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.0.6 Leonis: .NET bin onlyDownload latest release – v.5.0.6 Leonis: JAVA bin onlyDownload latest release – v.5.0.6 Leonis: bin + doc

NEWS FROM MATHPARSER.ORG
SOURCE CODE

Source code .zipSource code .tar.gz
View on GitHubMathSpace.pl

DONATION
Did you find the software useful?
Please consider donation 🙂
DONATE