Engee documentation
Notebook

Mathematical analysis

In this example, we will demonstrate the solution of several simple problems from the field of mathematical analysis – the construction of tangent lines, symbolic differentiation of equations, and finding the Jacobian of a system of equations.

First, run the preparation cell with the code.

In [ ]:
Pkg.add(["Latexify", "Symbolics"])
In [ ]:
using Latexify
using Symbolics
using Plots
using Printf
plotlyjs();
WARNING: using Plots.translate in module Main conflicts with an existing identifier.

Building a tangent line

Find the intersection point of the Y-axis and the line tangent to the sine wave at the point .

In [ ]:
a = pi/3

# Graph of a sine wave
plot(sin, -pi:0.1:pi, framestyle = :origin, legend=false)

# Points, graphs through which the secant should pass
scatter!(sin, [a])

# Equation of the tangent at pi/3
tangent(x) = sin(a) + cos(a)*(x - a)

# Graph of the tangent at pi/3
plot!(tangent, -3:2)

# The point where the secant line intersects the y axis
scatter!([0], [tangent(0)], c=:yellow)

# Summary of the result (with a couple of spaces at the end)
annotate!(0, касательная(0), text(@sprintf("%.3f", касательная(0))*"  ", :blue, :right, 8))
20.10 08:16:02.694 ⚠️  Framestyle :origin is not supported by Plotly and PlotlyJS. :zerolines was chosen instead.
Out[0]:
In [ ]:
println("The point where the tangent intersects the ordinate axis: (0, " * string(касательная(0)) * ")")
Точка, в которой касательная пересекает ось ординат: (0, 0.34242662818613967)

Symbolic differentiation

Differentiate the function .

In [ ]:
@Symbolics.variables t
Df = Symbolics.Differential(t); # Let's create a differentiation operator
z = t + t^2; # Let's define a function whose derivative needs to be found

# Let's differentiate the function and simplify the result.
expand_derivatives(Df(z))
Out[0]:
$$ \begin{equation} 1 + 2 t \end{equation} $$

Jacobian of the system of equations

Find the Jacobian of a system of linear functions:

In [ ]:
@Symbolics.variables x_1 x_2 x_3 a_11 a_12 a_13 a_21 a_22 a_23 a_31 a_32 a_33 b_1 b_2 b_3

Symbolics.jacobian([ a_11*x_1 + a_12*x_2 + a_13*x_3 - b_1 ; 
                     a_21*x_1 + a_22*x_2 + a_23*x_3 - b_2 ;
                     a_31*x_1 + a_32*x_2 + a_33*x_3 - b_3 ], [x_1, x_2, x_3])
Out[0]:
$$ \begin{equation} \left[ \begin{array}{ccc} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \\ \end{array} \right] \end{equation} $$