User defined arguments

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: 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());
Res 1: n*( sin(x+y)-cos(y/z) ) = 5.365883939231585
Res 2: n*( sin(x+y)-cos(y/z) ) = -1.2246467991473533E-15
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());
Res 1: y = 1.0
Res 2: y = 4.0
Res 3: y = 9.0
Res 4: x*y = 27.0

*** 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