Solving equation f(x) = 0

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: Solve 2x-4 = 0 for x in [0, 10]

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("solve( 2*x - 4, x, 0, 10 )");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: solve( 2*x - 4, x, 0, 10 ) = 2.0

Case 2: Solve cos(x) = 0 for x in [0, pi]

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("solve( cos(x), x, 0, pi )");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: solve( cos(x), x, 0, pi ) = 1.57079633

Case 3: Solve cos(x) = 0 for x in [pi, pi] (root not bracketed)

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("solve( cos(x), x, -pi, pi )");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: solve( cos(x), x, -pi, pi ) = -1.57079633
[mXparser-v.4.0.0] Res: solve( cos(x), x, -pi, pi ) = 1.57079633

Case 4: Solve x-y = 0 for x in [0, 10] and y = 4

import org.mariuszgromada.math.mxparser.*;
...
Argument y = new Argument("y = 4");
Expression e = new Expression("solve( x-y, x, 0, 10 )", y);
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: solve( x-y, x, 0, 10 ) = 4.0

Case 5: Solve sin'(x) = 0 for x in [0, pi]

import org.mariuszgromada.math.mxparser.*;
...
Argument x = new Argument("x");
Expression e = new Expression("solve( der( sin(x), x ), x, 0, pi )", x);
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: solve( der( sin(x), x ), x, 0, pi ) = 1.57079633

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