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.
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
Tahnk you very much for this video
Thank you!
Thank you very much for your tutorial!
Thank you for your interest and comment!
Great! Thank you very much!
Thank you for a nice comment! I appreciate it!
What if we want to to receive also the values of x1 ( in the case of pendulum the angle of oscillation) ?
Sorry, no time to address this question.
Amazing tutorial!
Glad you think so!
Muchas gracias!
Thank you!
Thanks. I have a question, what if we cast alpha as a vector, as in LLG equation? Thanks
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.
@@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.
@@valevan14 Hi, currently I do not have time to inspect your code. Best, A. Haber
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.
I am not sure. This is how you numerically solve differential equations. That is, by transforming them into state-space models.
thx bro for this video
Welcome
W
?