Skip to content

Differentiation

WhiteBlackGoose edited this page Feb 15, 2023 · 1 revision

Analytical differentation is available in AngouriMath.

Differentiation

This is fairly simple process of analytical computations of a derivative of an expression over one variable. To perform it, call method Differentiate. Example:

Entity expr = "a x ^ 2 + b sin(x) + c";
Console.WriteLine(expr.Differentiate("x"));

Output:

2 * x * a + cos(x) * b

If no derivative can be found, it will return node Entity.Derivativef. It might happen if the differentiated expression is not numerical, for example:

Entity expr = "a and x";
Console.WriteLine(expr.Differentiate("x"));

Output:

derivative(a and x, x)

It will also happen with subexpressions when they cannot be evaluated. For example,

Entity expr = "{ 1, 2 } + sin(x)";
Console.WriteLine(expr.Differentiate("x"));

Output:

derivative({ 1, 2 }, x) + cos(x)

You can also use this node in your expressions, and if the first argument of this node is a numerical node, then InnerSimplified and Simplify will execute differentiation. Example:

Entity expr = "x derivative(sin(x) + a x, x) + 16";
Console.WriteLine(expr.Simplify());

Output:

16 + (cos(x) + a) * x

You can also pass the third argument. It reflects the number of sequential differentiation of the same expression. Example:

Entity expr = "derivative(sin(x), x, 2)";
Console.WriteLine(expr.Simplify());
Entity expr2 = "derivative(derivative(sin(x), x), x)";
Console.WriteLine(expr2.Simplify().InnerSimplified);

Output:

-sin(x)
-sin(x)

In other words, derivative(sin(x), x, 2) is the second derivative of sin(x) or derivative of sin(x) of order 2.

Extension: string.Differentiate(Variable).

Clone this wiki locally