Skip to content

Differentiation

Rafael Vuijk edited this page Oct 1, 2026 · 3 revisions

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)

Adding a number to a set adds it to every element, so differentiating one differentiates every element — and the two derivatives here coincide, leaving a one-element set:

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

Output:

{ 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 + x * (cos(x) + a)

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