Engee documentation
Notebook

Graphical comparison of exponential functions

This example discusses a graphical approach to determining the larger of two values: $e^\pi$ and $\pi^e$.

To graphically compare the values of $e^\pi$ and $\pi^e$, we plot the surface of the difference function of the exponential functions $z=x^y-y^x$.

To do this, first load and connect the library PlotlyJS.

In [ ]:
import Pkg
Pkg.add("PlotlyJS")
using PlotlyJS;
   Resolving package versions...
  No Changes to `/user/.project/Project.toml`
  No Changes to `/user/.project/Manifest.toml`

Let's define arrays of surface coordinates.

In [ ]:
x = 0:0.10:5;
y = 0:0.10:5;
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;

Let's define the function SurfPlot for drawing the surface, in which the parameters of design elements and drawing area overview are also set.

In [ ]:
function SurfPlot(surf)
    PlotlyJS.plot(surf,
        Layout(
            title=attr(
            text="Сравнение показательных функций",
            x=0.5 # выравнивание текста
            ),
        scene=attr(
            camera_eye=attr(x=0.5, y=-0.8, z=0.6), # углы обзора
            aspectratio=attr(x=0.5, y=0.5, z=0.5) # масштабирование осей
            )
        )
    )
end;

Let's build the surface by the defined function.

In [ ]:
surf = PlotlyJS.surface(x = X, y = Y, z = Z)
SurfPlot(surf)
Out[0]:

In the plane $Z=0$ draw the contour on the constructed surface.

In [ ]:
surf = PlotlyJS.surface(
    x = X, y = Y, z = Z,
    contours = attr(
        z=attr(
            show=true,
            start=0.0, # начальный уровень контуров
            size=1.0, # шаг нанесения контуров
            color="black"
        ),
        z_end = 0.1 # конечный уровень контуров
    )
)

SurfPlot(surf)
Out[0]:

On the constructed contours there are several points of integer solutions of the equation $x^y-y^x=0$. Let us plot these points on the contours.

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

scat = PlotlyJS.scatter3d(
    x=ix, y=iy, z=iz,
    mode="markers",
    showlegend=false,
    marker=attr(
        size=6,
        color="black"
        )
)

SurfPlot([surf,scat])
Out[0]:

Now plot the function points for the sought $x$ and $y$ at the coordinates: $(\pi, e, \pi^e-e^\pi)$ and $(e, \pi, e^\pi-\pi^e)$.

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

scat2 = PlotlyJS.scatter3d(
    x=tx, y=ty, z=tz,
    mode="markers",
    showlegend=false,
    hovertext=["pi^e-e^pi", "e^pi-pi^e"],
    marker=attr(
        size=6,
        color="green",
        
    )
)

SurfPlot([surf, scat, scat2])
Out[0]:

The construction shows that the point with coordinates $(e, \pi, e^\pi-\pi^e)$ is located in the part of the surface that is above the plane $Z = 0$, and the point $(\pi, e, \pi^e-e^\pi)$ - in the part of the surface below the secant plane. The same can be set when hovering the cursor over these points in the construction area.

From this we can conclude that the value $e^\pi$ is greater than $\pi^e$. In confirmation let's calculate these values.

In [ ]:
e^pi
Out[0]:
23.140692632779263
In [ ]:
pi^e
Out[0]:
22.459157718361038

Conclusion

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