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

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ม.ค. 2025

ความคิดเห็น • 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 TH-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!

    • @aleksandarhaber
      @aleksandarhaber  2 ปีที่แล้ว +1

      Thank you for your interest and comment!

  • @lucasmelo6987
    @lucasmelo6987 9 หลายเดือนก่อน

    Amazing tutorial!

  • @TheGameDuke
    @TheGameDuke ปีที่แล้ว +1

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

    • @aleksandarhaber
      @aleksandarhaber  ปีที่แล้ว +1

      Sorry, no time to address this question.

  • @edsondepinhodasilva3696
    @edsondepinhodasilva3696 ปีที่แล้ว +1

    Great! Thank you very much!

    • @aleksandarhaber
      @aleksandarhaber  ปีที่แล้ว +1

      Thank you for a nice comment! I appreciate it!

  • @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.

  • @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

  • @Elionas
    @Elionas 11 หลายเดือนก่อน +1

    thx bro for this video

  • @dariya123iqbal7
    @dariya123iqbal7 ปีที่แล้ว +1

    W