summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/hybrid-latex/examples/example-03.tex
blob: abb9863d099dcd0aeb14cbdbdac6edff0523e583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% based on example 8 in pythontex_gallery
% https://github.com/gpoore/pythontex/

\documentclass[12pt]{pylatex}
\usepackage{examples}

\begin{document}

\section*{Step-by-step integration}

This is another nice example drawn from the Pythontex gallery, see
\ \url{https://github.com/gpoore/pythontex}.

It shows the step-by-step computations of a simple triple integral.

\begin{python}
   from sympy import *

   x, y, z = symbols('x,y,z')
   f = Symbol('f(x,y,z)')

   # Define limits of integration
   x_max = 2;   y_max = 3;   z_max = 4;
   x_min = 0;   y_min = 0;   z_min = 0;

   lhs = Integral(f, (x, x_min, x_max),
                     (y, y_min, y_max),
                     (z, z_min, z_max))                   # py(lhs.01,lhs)

   f = x*y + y*sin(z) + cos(x+y)

   rhs = Integral(f, (x, x_min, x_max),
                     (y, y_min, y_max),
                     (z, z_min, z_max))                   # py(rhs.01,rhs)
   rhs = Integral(Integral(f, (x, x_min, x_max)).doit(),
                              (y, y_min, y_max),
                              (z, z_min, z_max))          # py(rhs.02,rhs)
   rhs = Integral(Integral(f, (x, x_min, x_max),
                              (y, y_min, y_max)).doit(),
                              (z, z_min, z_max))          # py(rhs.03,rhs)
   rhs = Integral(f, (x, x_min, x_max),
                     (y, y_min, y_max),
                     (z, z_min, z_max)).doit()            # py(rhs.04,rhs)

   # And now, a numerical approximation
   rhs = N(rhs)                                           # py(rhs.05,rhs)

\end{python}

\begin{minipage}[t]{0.65\textwidth}
\begin{align*}
   \py{lhs.01} &= \py{rhs.01}\\
               &= \py{rhs.02}\\
               &= \py{rhs.03}\\
               &= \py{rhs.04}\\[8pt]
               &\approx \py{rhs.05}
\end{align*}
\end{minipage}
\hskip 1cm
\lower16pt\hbox{%
\begin{minipage}[t]{0.35\textwidth}
\begin{latex}
   \begin{align*}
      \py{lhs.01} &= \py{rhs.01}\\
                  &= \py{rhs.02}\\
                  &= \py{rhs.03}\\
                  &= \py{rhs.04}\\[8pt]
                  &\approx \py{rhs.05}
   \end{align*}
\end{latex}
\end{minipage}}

\end{document}