User defined arguments

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: Dealing with free arguments

$$x,y, z,\ldots\in\mathbb{R}$$

$$\sin(x+y)-\cos(\frac{y}{z})$$

import org.mariuszgromada.math.mxparser.*;
...
Argument x = new Argument("x = 1");
Argument y = new Argument("y = 2*pi");
Argument z = new Argument("z", 3);
Argument n = new Argument("n", 4);
         
Expression e = new Expression("n*( sin(x+y)-cos(y/z) )", x, y, z, n);
mXparser.consolePrintln("Res 1: " + e.getExpressionString() + " = " + e.calculate());
 
x.setArgumentValue(0);
z.setArgumentValue(4);
mXparser.consolePrintln("Res 2: " + e.getExpressionString() + " = " + e.calculate());
 
x.setArgumentValue(5);
mXparser.consolePrintln("Res 3: " + x.getArgumentName() + " = " + x.getArgumentValue());
[mXparser-v.5.0.0] Res 1: n*( sin(x+y)-cos(y/z) ) = 5.365883939231586
[mXparser-v.5.0.0] Res 2: n*( sin(x+y)-cos(y/z) ) = 0.0
[mXparser-v.5.0.0] Res 3: x = 5.0

Case 2: Defining dependent arguments

$$y=x^2$$

import org.mariuszgromada.math.mxparser.*;
...
Argument x = new Argument("x");     
Argument y = new Argument("y = x^2", x);
         
x.setArgumentValue(1);
mXparser.consolePrintln("Res 1: " + y.getArgumentName() + " = " + y.getArgumentValue());
         
x.setArgumentValue(2);
mXparser.consolePrintln("Res 2: " + y.getArgumentName() + " = " + y.getArgumentValue());
         
x.setArgumentValue(3);
mXparser.consolePrintln("Res 3: " + y.getArgumentName() + " = " + y.getArgumentValue());
         
Expression e = new Expression("x*y", x, y);
mXparser.consolePrintln("Res 4: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] Res 1: y = 1.0
[mXparser-v.5.0.0] Res 2: y = 4.0
[mXparser-v.5.0.0] Res 3: y = 9.0
[mXparser-v.5.0.0] Res 4: x*y = 27.0

Case 3: Implementing your own Argument Extension

import org.mariuszgromada.math.mxparser.*;
...
class PiMultArgExt implements ArgumentExtension {
    private int multiple = 0;
    public double getArgumentValue() {
        multiple++;
        return  MathConstants.PI * multiple;
    }
    public PiMultArgExt clone() {
        return new PiMultArgExt();
    }
}
import org.mariuszgromada.math.mxparser.*;
...
Argument pim = new Argument("pim", new PiMultArgExt());
Expression e = new Expression("pim", pim);
mXparser.consolePrintln("Res: 1st call: " + e.getExpressionString() + " = " + e.calculate());
mXparser.consolePrintln("Res: 2nd call: " + e.getExpressionString() + " = " + e.calculate());
mXparser.consolePrintln("Res: 3rd call: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] Res: 1st call: pim = 3.141592653589793
[mXparser-v.5.0.0] Res: 2nd call: pim = 6.283185307179586
[mXparser-v.5.0.0] Res: 3rd call: pim = 9.42477796076938
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