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{xcoord(t) = x0 + vox * t}
      • \text{ycoord(t) = y0 + voy * t - g * t^2 / 2}
    • Exemplu de parametri:
      • tmax=4, numpoints =10t_{max} = 4, \text{ numpoints } = 10
      • t=np.linspace(0,tmax,numpoints)t = \text{np.linspace}(0, t_{max}, \text{numpoints})
      • x0=0;y0=19;v0=27;th=30;g=9.81x0 = 0; y0 = 19; v0 = 27; th = 30; g = 9.81
      • vox=v0∗np.cos(np.deg2rad(th))vox = v0 * \text{np.cos(np.deg2rad(th))}
      • voy=v0∗np.sin(np.deg2rad(th))voy = v0 * \text{np.sin(np.deg2rad(th))}
      • x=xcoord(t)x = \text{xcoord(t)}
      • y=ycoord(t)y = \text{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ă:
    • dx(t)dt=−2x(t),x(0)=1\frac{dx(t)}{dt} = -2x(t), x(0) = 1
    • import numpy as np
    • from scipy.integrate import odeint
    • import matplotlib.pyplot as plt
    • def functie (x, t):
      • return -2*x
    • time_vec = np.linspace (0, 4, 40)
    • x_ini = 1
    • xvec = 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):
    • d2x(t)dt2=−μmdx(t)dt\frac{d^2x(t)}{dt^2} = - \frac{\mu}{m} \frac{dx(t)}{dt}
    • d2y(t)dt2=−g−μmdy(t)dt\frac{d^2y(t)}{dt^2} = -g - \frac{\mu}{m} \frac{dy(t)}{dt}
  • Exemplu: Linii de câmp electric