Derivatives & Integrals

mXparser - logo

*** If you found the software useful donation is something you might consider 🙂 ***

If you found the software useful donation is something you might consider :-)

JAVA code

Case 1: General derivative

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.4.1.0] Res: cos(1) - der(sin(x), x, 1) = 8.58862758690293E-10

Case 1 (alternative syntax): General derivative

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.4.1.0] Res: cos(x) - der(sin(x), x) = 8.58862758690293E-10

Case 2: Left / right derivative

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.4.1.0] Res 1: der-(abs(x), x, 0) = -1.0
[mXparser-v.4.1.0] Res 2: der+(abs(x), x, 0) = 1.0

Case 2 (alternative syntax): Left / right derivative

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.4.1.0] Res 1: der-(abs(x), x) = -1.0
[mXparser-v.4.1.0] Res 2: der+(abs(x), x) = 1.0

Case 3: Derivative from more complex function

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.4.1.0] Res 1: cos(1) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x, 1) = 8.59431192878901E-10
[mXparser-v.4.1.0] Res 2: cos(2) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x, 2) = -2.646203534073521E-9
[mXparser-v.4.1.0] Res 3: cos(3) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x, 3) = -1.599625543136085E-9

Case 3 (alternative syntax): Derivative from more complex function

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.4.1.0] Res 1: cos(x) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x) = 8.59431192878901E-10
[mXparser-v.4.1.0] Res 2: cos(x) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x) = -2.646203534073521E-9
[mXparser-v.4.1.0] Res 3: cos(x) - der( sum(k,0,10,(-1)^k*(x^(2*k+1))/(2*k+1)!), x) = -1.599625543136085E-9

Case 4: 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());
Res: 2 * int( sqrt(1-x^2), x, -1, 1 ) = 3.1415920928388927

*** If you found the software useful donation is something you might consider 🙂 ***

If you found the software useful donation is something you might consider :-)

Enjoy! 🙂

 

Best regards,

Mariusz Gromada

Download latest release – v.4.1.1 Aeries: bin + doc + src (.zip 13.4 MB)

Download latest release – v.4.1.1 Aeries: bin only (.zip 4.35 MB) – separate binaries for java: 1.5, 1.6, 1.7, 1.8; .NET: 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, 4.7, .NET Core, .NET Standard, .NET PCL, Xamarin.Android, Xamarin.iOS

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