Solve Differential Equations in Python by Using odeint() SciPy Function

Поділитися
Вставка
  • Опубліковано 21 гру 2024
  • #python #pythonprogramming #scipy #pythonnumpy #numerical #differentialequation #ode45 #numericalsolution #dynamicalsystems #pendulum #mathematics #calculus #numericalanalysis
    If you need help with your professional engineering problem, or you need to develop new skills in the fields of control, signal processing, embedded systems, programming, optimization, machine learning, robotics, etc., we are here to help. We provide professional engineering services as well as tutoring and skill development services. We have more than 15 years of industry, research, and university-level teaching experience. Describe your problem and we will send you a quote for our services. The contact information is ml.mecheng@gmail.com
    It takes a significant amount of time and energy to create these free video tutorials. You can support my efforts in this way:
    Buy me a Coffee: www.buymeacoff...
    PayPal: www.paypal.me/...
    Patreon: www.patreon.co...
    You Can also press the Thanks UA-cam Dollar button
    The post accompanying this UA-cam tutorial is given here: aleksandarhabe...
    In this video and in the accompanying post, we explain how to solve ordinary differential equations in Python. We use the SciPy Python function odeint(). We explain the solution method by using a differential equation describing the dynamics of a damped pendulum. We also explain how to define a state-space model of the ordinary differential equation.

КОМЕНТАРІ • 23

  • @aleksandarhaber
    @aleksandarhaber  2 роки тому +1

    If you need help with your professional engineering problem, or you need to develop new skills in the fields of control, signal processing, embedded systems, programming, optimization, machine learning, robotics, etc., we are here to help. We provide professional engineering services as well as tutoring and skill development services. We have more than 15 years of industry, research, and university-level teaching experience. Describe your problem and we will send you a quote for our services. The contact information is ml.mecheng@gmail.com
    It takes a significant amount of time and energy to create these free video tutorials. You can support my efforts in this way:
    - Buy me a Coffee: www.buymeacoffee.com/AleksandarHaber
    - PayPal: www.paypal.me/AleksandarHaber
    - Patreon: www.patreon.com/user?u=32080176&fan_landing=true
    - You Can also press the Thanks UA-cam Dollar button

  • @Camille-wr6vh
    @Camille-wr6vh Рік тому +2

    Tahnk you very much for this video

  • @kikito6316
    @kikito6316 2 роки тому +1

    Thank you very much for your tutorial!

  • @edsondepinhodasilva3696
    @edsondepinhodasilva3696 Рік тому +1

    Great! Thank you very much!

  • @TheGameDuke
    @TheGameDuke Рік тому +1

    What if we want to to receive also the values of x1 ( in the case of pendulum the angle of oscillation) ?

  • @lucasmelo6987
    @lucasmelo6987 8 місяців тому

    Amazing tutorial!

  • @jccasava2035
    @jccasava2035 Рік тому +1

    Muchas gracias!

  • @valevan14
    @valevan14 2 роки тому +1

    Thanks. I have a question, what if we cast alpha as a vector, as in LLG equation? Thanks

    • @aleksandarhaber
      @aleksandarhaber  2 роки тому +1

      You need to write a state-space model in order to solve the equation. In my example, alpha is a state variable of the pendulum. If you are talking about this equation, en.wikipedia.org/wiki/Landau%E2%80%93Lifshitz%E2%80%93Gilbert_equation then alpha is a constant, if I am not mistaken. In any case, before solving the problem, the idea is to write a state-space model.

    • @valevan14
      @valevan14 2 роки тому +1

      @@aleksandarhaber Thanks for the reply. I actually solved the problem this way. I am unsure as why this works:
      import numpy as np
      from scipy.integrate import odeint
      import matplotlib.pyplot as plt
      def LLG_equation(m,t,gamma,delta):
      dmdt= -gamma * (np.cross(m, h_eff)) + \
      delta * (np.cross(m, np.cross(m, h_eff)))
      return dmdt
      np.random.seed(12345)
      #define the constants
      m = 0.2
      h = 0.5
      alpha = 0.5
      gamma = 1/(1+alpha**2)
      delta = alpha/(1+alpha**2)
      # set the initial conditions
      m1 = m*normvec(3)
      m2 = m*normvec(3)
      h_eff = h*np.array([0,0,1])
      m_arr = np.array([m1, m2])

      # define the discretization points
      timePoints=np.linspace(0,100,300)
      # Plot for m1_x
      solutionOde_m1 = odeint(LLG_equation, m1, timePoints, args = (gamma, delta))
      plt.plot(timePoints, solutionOde_m1[:,0], 'b', label=r'$m_1^x$')
      plt.plot(timePoints, solutionOde_m1[:,1], 'g', label=r'$m_1^y$')
      plt.plot(timePoints, solutionOde_m1[:,2], 'r', label=r'$m_1^z$')
      plt.legend(loc = 'best')
      plt.xlabel('time')
      plt.ylabel(r'$m_1^x(t), m_1^y(t), m_1^z(t)$')
      plt.grid()
      plt.show()
      I was trying just now to put in the state space part by inserting [...,0] but it's not working. But my aim is to simulate not only one vector m1, but at least 2 vectors m1 and m2 simultaneously.

    • @aleksandarhaber
      @aleksandarhaber  2 роки тому +1

      @@valevan14 Hi, currently I do not have time to inspect your code. Best, A. Haber

  • @emrebahceci9965
    @emrebahceci9965 Рік тому +1

    All Python codes I've seen so far use the state-space form in order to solve differential equations. Is there another way? By the way, thanks for great video.

    • @aleksandarhaber
      @aleksandarhaber  Рік тому +2

      I am not sure. This is how you numerically solve differential equations. That is, by transforming them into state-space models.

  • @Elionas
    @Elionas 10 місяців тому +1

    thx bro for this video

  • @dariya123iqbal7
    @dariya123iqbal7 Рік тому +1

    W