Solving equation f(x) = 0

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: 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.5.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.5.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.5.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.5.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.5.0.0] Res: solve( der( sin(x), x ), x, 0, pi ) = 1.57079633
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