Python - biblioteci, numpy, matplotlib, scipy
Python - Biblioteci
- numpy: îmbunătățiri pentru operații numerice, în special calcul matriceal.
- scipy: algoritmi numerici pentru integrare, derivare, rezolvare de ecuații liniare și ecuații diferențiale.
- matplotlib: reprezentări grafice.
Python - numpy
import numpy as np- Exemplu de calcul al coordonatelor:
- Definire funcții:
- xcoord(t) = x0 + vox * t
- \text{ycoord(t) = y0 + voy * t - g * t^2 / 2}
- Exemplu de parametri:
- tmax=4, numpoints =10
- t=np.linspace(0,tmax,numpoints)
- x0=0;y0=19;v0=27;th=30;g=9.81
- vox=v0∗np.cos(np.deg2rad(th))
- voy=v0∗np.sin(np.deg2rad(th))
- x=xcoord(t)
- y=ycoord(t)
Python - matplotlib
- Exemplu de reprezentare grafică:
fig, ax = plt.subplots()ax.scatter(x, y, s=100)ax.plot(x, y)plt.show()
Python - scipy
- Exemplu de ecuație diferențială:
- dtdx(t)=−2x(t),x(0)=1
import numpy as npfrom scipy.integrate import odeintimport matplotlib.pyplot as pltdef functie (x, t):time_vec = np.linspace (0, 4, 40)x_ini = 1xvec = odeint(functie, x_ini, time_vec)fig, ax = plt.subplots()ax.plot(time_vec, xvec)plt.show
- Exemplu de modificare a ecuației diferențiale (frecare cu aerul):
- dt2d2x(t)=−mμdtdx(t)
- dt2d2y(t)=−g−mμdtdy(t)
- Exemplu: Linii de câmp electric