Math Tutorial¶
Jupyter notebooks¶
Through jupyter notebooks you can upload examples of math and programming implementations and also you can display complex Latex style equations such as the famous Pitagoras theorem: \begin{equation} a^2 + b^2 = c^2 \end{equation} and then uses the python program executed in the jupyter notebook as in
import math
a = 4 # Cateto A
b = 3 # Cateto B
c = math.sqrt(a**2 + b**2) # Operacion del cálculo
#Imprimir resultado
print(c)
5.0
It also allows you to import librarys from your computer and only display the results in the web page. As an example, the libraries numpy, scipy and matplotlib. The first library can be used in for numerical computation, indeed, numpy stays for NUMerical PYthon. SCIentific Python is another library that can be used for the modelling of dynamical systems in engineering classes. The third library can be used for plotting results.
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
With these libraries, we can simulate the lorentz attractor. the lorentz attractor along with other systems such as the double pendulum, is used to explain the chaos in dynamical systems. The differential equations that describes the systems are \begin{align} \dot{x} = \sigma \left(y-x\right) \\ \dot{y} = x \left(\rho-z\right)-y \\ \dot{z} = xy-\beta z \\ \end{align} with the parameters given by $\sigma=10$, $\beta=\frac{8}{3}$ and $\rho=28$. The initial conditions as $x=y=z=1$. The program is the following:
sigma = 10
beta = 8/3
rho = 28
def f(iState,t):
x = iState[0]
y = iState[1]
z = iState[2]
return sigma*(y-x), x*(rho-z)-y, x*y-beta*z
So = np.array([1,1,1])
t = np.arange(0.0,40.0,0.01)
system = odeint(f,So,t)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(system[:, 0], system[:, 1], system[:, 2])
plt.show()