Simple expressions

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

$$2+1$$

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

Case 2: Changing expression string

$$2-1$$

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2+1");
e.setExpressionString("2-1");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] 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());
[mXparser-v.5.0.0] Res: 2-(32-4)/(23+4/5)-(2-4)*(4+6-98.2)+4 = -171.57647058823528

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());
[mXparser-v.5.0.0] 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.5.0.0] Res 1: 1.2e2 + 1.2e+2 + 1.2e-2 = 240.012
[mXparser-v.5.0.0] Res 2: 1.2E2 + 1.2E+2 + 1.2E-2 = 240.012

Case 6: Percent sign support

import org.mariuszgromada.math.mxparser.*;
...
Expression e1 = new Expression("2%");
Expression e2 = new Expression("2% * 100");
Expression e3 = new Expression("pi% * 100");
mXparser.consolePrintln("Res 1: " + e1.getExpressionString() + " = " + e1.calculate());
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate());
mXparser.consolePrintln("Res 3: " + e3.getExpressionString() + " = " + e3.calculate());
[mXparser-v.5.0.0] Res 1: 2% = 0.02
[mXparser-v.5.0.0] Res 2: 2% * 100 = 2.0
[mXparser-v.5.0.0] Res 3: pi% * 100 = 3.1415926535897936

Case 7: Leading zeros support

import org.mariuszgromada.math.mxparser.*;
...
Expression e1 = new Expression("00123");
Expression e2 = new Expression("-00123");
Expression e3 = new Expression("-00000123.123e-10");
mXparser.consolePrintln("Res 1: " + e1.getExpressionString() + " = " + e1.calculate());
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate());
mXparser.consolePrintln("Res 3: " + e3.getExpressionString() + " = " + e3.calculate());
[mXparser-v.5.0.0] Res 1: 00123 = 123.0
[mXparser-v.5.0.0] Res 2: -00123 = -123.0
[mXparser-v.5.0.0] Res 3: -00000123.123e-10 = -1.23123E-8
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.0.7

Nuget – .NET CLI

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

Nuget – Package Reference

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

Maven – Dependency

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

Maven – Gradle

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

Maven – Gradle (Kotlin)

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

GitHub

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

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.0.7 Leonis: .NET bin onlyDownload latest release – v.5.0.7 Leonis: JAVA bin onlyDownload latest release – v.5.0.7 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