AngouriMath
Solvers
Here we shall review different ways to solve equations, inequalities, statements, systems.
Solving a classic equation
The method to solve a classic equation over a single variable in AM isEntity expr = "2sin(a x) - b";
Console.WriteLine(expr.SolveEquation("x"));
Output:
{ (arcsin(b / 2) + 2 * pi * n_1) / a, (pi - arcsin(b / 2) + 2 * pi * n_1) / a }
Nonetheless, AM allows you to solve Solving a statement
AEntity expr = "x2 = 16";
Console.WriteLine(expr.Solve("x"));
Output:
{ 4, -4 }
Here is a more advanced example:
Entity expr = "x4 = 16 and x in RR and x > 0";
Console.WriteLine(expr.Solve("x"));
Output:
{ 2 }
Adding another condition:
Entity expr = "x4 = 16 and x in RR and x > 0 or x^a = 6";
Console.WriteLine(expr.Solve("x"));
Output:
{ 2, 6 ^ (1 / a) }
Example with inequalities:
Entity expr = "2x2 - 3 > 0 and x > 0";
Console.WriteLine(expr.Solve("x").Simplify());
Entity expr2 = "2x2 - 3 > 0 or x > 0";
Console.WriteLine(expr2.Solve("x").Simplify());
Output:
((-oo; -sqrt(24) / 4) \/ (sqrt(24) / 4; +oo)) /\ (0; +oo)
(-oo; -sqrt(24) / 4) \/ (sqrt(24) / 4; +oo) \/ (0; +oo)
Extension: Entity expr = "a x2 + b x + c = 0";
var solutions = expr.Solve("x");
if (solutions is Entity.Set.FiniteSet finiteSet)
{
foreach (var root in finiteSet)
Console.WriteLine($"Root: {root}");
}
Output:
Root: (-b - sqrt(b ^ 2 - 4 * a * c)) / (2 * a)
Root: (-b + sqrt(b ^ 2 - 4 * a * c)) / (2 * a)
Solving system of equations
Every equation of the system should be written as a simple equation (as in the first part of the article). The method ofvar system = Equations(
"x2 + a y3",
"y - x - b"
);
This creates an instance of Console.WriteLine(system);
Output:
x ^ 2 + a * y ^ 3 = 0
y - x - b = 0
The method var system = Equations(
"x2 + y",
"y - x - 3"
);
Console.WriteLine(system.Solve("x", "y"));
Output:
Matrix[2 x 2]
(1 - sqrt(-11)) / (-2) -((1 - sqrt(-11)) / (-2)) ^ 2
(1 + sqrt(-11)) / (-2) -((1 + sqrt(-11)) / (-2)) ^ 2
The first (left) column are values for Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 1534 pages online