Engee documentation
Notebook

Graphical comparison of exponential functions

This example discusses a graphical approach to determining the larger of two values: and .

To graphically compare the values of and , we plot the surface of the difference function of the exponential functions .

To do this, first of all, install and connect the library CairoMakie.

In [ ]:
import Pkg; Pkg.add("CairoMakie");
using CairoMakie;

Let's define arrays of surface coordinates.

In [ ]:
x = 0:0.05:4; y = 0:0.05:4;
X = [i for i in x, j in 1:length(y)]; Y = [j for i in 1:length(x), j in y];
Z = X.^Y-Y.^X;

Build the surface by the given function.

In [ ]:
using CairoMakie

# Создаем фигуру и 3D оси
fig = Figure(;size = (600, 600));
ax = Axis3(fig[1, 1], 
          title = "Показательные функции",
          xlabel = "Ось X", ylabel = "Ось Y", zlabel = "Ось Z",
          aspect=(1,1,1), azimuth=-pi*0.64);

# Создаём поверхность
CairoMakie.surface!(ax, x, y, Z, 
                    colormap = :prism,
                    colorrange = (minimum(Z), maximum(Z)));

# Добавляем цветовую шкалу
Colorbar(fig[1, 2],
         limits = (minimum(Z), maximum(Z)),
         colormap = :prism, label = "Значения");

display(fig);
No description has been provided for this image

In the plane draw the contour on the constructed surface.

In [ ]:
CairoMakie.contour3d!(ax, x, y, Z,
                      levels = [0],
                      color=:black, linewidth=2)
display(fig);
No description has been provided for this image

On the constructed contours there are several points of integer solutions of the equation . Let us plot these points on the contours.

In [ ]:
# массивы целочисленных решений уравнения
ix=[0,1,2,2,3,4,4] 
iy=[0,1,2,4,3,2,4]
iz=zeros(7)

CairoMakie.scatter!(ax, ix, iy, iz;
                    color=:black)
display(fig);
No description has been provided for this image

Now plot the function points for the sought and at the coordinates: and .

In [ ]:
e=exp(1);
tx=[pi,e]
ty=[e,pi]
textt=["pi,e", "e,pi"]
tz=tx.^ty-ty.^tx

CairoMakie.scatter!(ax, tx, ty, tz;
                    color=:white)
CairoMakie.text!(ax, tx, ty, tz;
                 text = textt, align = (:right, :bottom),
                 color = :white)
display(fig);
No description has been provided for this image

From the construction we can see that the point with coordinates is located in the part of the surface that is above the plane , and the point - in the part of the surface below the secant plane. For convenience of viewing the location of points you can edit the azimuth of axes and code cell mask:

In [ ]:
Азимут=-0.38 # @param {type:"slider",min:-6.28,max:6.28,step:0.1}
ax.azimuth[] = Азимут;
display(fig);
No description has been provided for this image

From this we can conclude that the value of is greater than . In confirmation let's calculate these values.

In [ ]:
@show e^pi, pi^e;
(e ^ pi, pi ^ e) = (23.140692632779263, 22.459157718361038)

Conclusion

In this example, we have looked at an illustrative way to graphically find the larger of two values.