Mathematical analysis
In this example we will demonstrate the solution of several simple problems from the field of mathematical analysis - drawing tangent lines, symbolic differentiation of equations and finding the Jacobian of a system of equations.
First, start the preparatory code cell.
In [ ]:
Pkg.add(["Latexify", "Symbolics"])
In [ ]:
using Latexify
using Symbolics
using Plots
using Printf
plotlyjs();
Drawing a tangent line
Find the point of intersection of the Y-axis and the line that is tangent to the sine wave at .
In [ ]:
a = pi/3
# График синусоиды
plot(sin, -pi:0.1:pi, framestyle = :origin, legend=false)
# Точки, графика, через которые должна пройти секущая
scatter!(sin, [a])
# Уравнение касательной в точке pi/3
касательная(x) = sin(a) + cos(a)*(x - a)
# График касательной в точке pi/3
plot!(касательная, -3:2)
# Точка, где секущая линия пересекает ось y
scatter!([0], [касательная(0)], c=:yellow)
# Аннотация результата (с парой пробелов в конце)
annotate!(0, касательная(0), text(@sprintf("%.3f", касательная(0))*" ", :blue, :right, 8))
Out[0]:
In [ ]:
println("Точка, в которой касательная пересекает ось ординат: (0, " * string(касательная(0)) * ")")
Symbolic differentiation
Differentiate the function .
In [ ]:
@Symbolics.variables t
Df = Symbolics.Differential(t); # Создадим оператор дифференцирования
z = t + t^2; # Зададим функцию, производную которой нужно найти
# Продифференцируем функцию и упростим результат
expand_derivatives(Df(z))
Out[0]:
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]: