Simple expressions

MathParser.org - mXparser - logo - Tutorial

*** 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: Simple calculation

2+1

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2+1");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
Res: 2+1 = 3.0

Case 2: Changing expression string

2-1

import org.mariuszgromada.math.mxparser.*;
...
e.setExpressionString("2-1");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
Res: 2-1 = 1.0

Case 3: Using operators

2-\frac{32-4}{23+\frac{4}{5}}-(2-4)(4+6-98.2)+4

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2-(32-4)/(23+4/5)-(2-4)*(4+6-98.2)+4");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
Res: 2-(32-4)/(23+4/5)-(2-4)*(4+6-98.2)+4 = -171.5764705882353

Case 4: Power function

2^3+2^{3}+2^{3^{-4}}

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2^3+2^(-3)+2^3^(-4)");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
Res: 2^3+2^(-3)+2^3^(-4) = 9.133594091576999

Case 5: Using numbers in scientific notation

import org.mariuszgromada.math.mxparser.*;
...
Expression e1 = new Expression("1.2e2 + 1.2e+2 + 1.2e-2");
mXparser.consolePrintln("Res 1: " + e1.getExpressionString() + " = " + e1.calculate() );
Expression e2 = new Expression("1.2E2 + 1.2E+2 + 1.2E-2");
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate() );
[mXparser-v.4.0.0] Res 1: 1.2e2 + 1.2e+2 + 1.2e-2 = 240.012
[mXparser-v.4.0.0] Res 2: 1.2E2 + 1.2E+2 + 1.2E-2 = 240.012

*** 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.0.0.2: bin + doc + src (.zip 10.7 MB)

Download latest release – v.4.0.0.2: bin only (.zip 3.04 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, .NET Core, .NET Standard, .NET PCL, Xamarin.Android, Xamarin.iOS

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