Solve ODEs in Python: Simple to Complex

  Рет қаралды 76,384

APMonitor.com

APMonitor.com

Күн бұрын

Пікірлер: 51
@NehalPatel26
@NehalPatel26 5 жыл бұрын
Excellent video, easy to follow and customise to different applications!
@jabsterjab168
@jabsterjab168 4 жыл бұрын
So easy to understand. It helps a lot for beginners. Thank you so much.
@apm
@apm 4 жыл бұрын
I'm glad it helped. Here are additional tutorials: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
@uthoshantm
@uthoshantm 5 жыл бұрын
Avoided the loop by passing u as a function representing the step function: def first_order(y, t, tau, K, u): dydt = (-y + K*u(t)) / tau return dydt t0 = 0 t1 = 10 intervals = 100 t = np.linspace(t0, t1, intervals) tau = 5.0 K = 2.0 u = lambda t: 0 if t < 3 else 1 y = odeint(first_order, 0, t, args=(tau, K, u)) plt.plot(t, y)
@apm
@apm 5 жыл бұрын
Thanks for the tip!
@colosusmind6846
@colosusmind6846 3 жыл бұрын
Hi, what if we had different values for U at every timepoint? It will be difficult to call u(t) in the ODE because the integrator adapts the time steps.
@luzzyrogue
@luzzyrogue 2 жыл бұрын
Great suggestion as this is faster
@peterbooker6342
@peterbooker6342 2 жыл бұрын
Great video! Around 14:25 you speak of accessing an array for the argument u. Is it possible to set up a seperate function that loops that array(11 terms) through your ode function, without manually updating that value one run at a time? I am currently struggling in my own research with a similar problem.
@apm
@apm 2 жыл бұрын
Sure, you could create some type of lookup function inside the derivative function. Here are other examples: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
@hannanwali8363
@hannanwali8363 2 жыл бұрын
In mixer model Ca value is changing with every new iteration. Can you please explain how it is happening, why it's value is not replaced by dCadt.
@apm
@apm 2 жыл бұрын
dCadt is the derivative of the Ca value. Here is additional help with this problem: apmonitor.com/pdc/index.php/Main/ControlBlending
@zeawoas
@zeawoas 6 жыл бұрын
to use varying input parameters in the ODE in general it is advised to provide the input values via an own function instead of storing them in a list which you build a loop around. This saves code and also avoids lower precision issues that arise when using large time steps (like those in the video) for the loop. In this example the function would look somewhat like: def u(t): if t < 3: return 0.0 else: return 1.0 this way you can just use u(t) in the 'firstorder'-function and conveniently stick to the standard odeint syntax.
@apm
@apm 6 жыл бұрын
I appreciate that suggestion. One thing that I found with the ODEINT integrator is that even though a larger step size is requested the integrator will internally and adaptively modify the steps size to maintain accuracy and then only report the final value of the interval that is requested. I often use the models in control applications where we need to update the inputs frequently and at a given time interval. I teach the way you mentioned as a first approach if we don't need to have many successive input changes that would overwhelm a conditional statement in the model. apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations One more benefit of your approach is that the integrator may even select larger step sizes than the loop increments if it is deemed that the accuracy can be maintained. This could save a lot of time for repeat calculations of points that could be interpolated.
@zeawoas
@zeawoas 6 жыл бұрын
Ah ok, I see. Thanks for the answer!
@gfraser92
@gfraser92 3 жыл бұрын
I seem to get an error when setting u = np.zeros(len(t)) . Get an error saying "RuntimeError: The size of the array returned by func (11) does not match the size of y0 (1)" Any advice?
@apm
@apm 3 жыл бұрын
Try the source code here: apmonitor.com/pdc/index.php/Main/TankBlending There are also related examples here: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations or here: apmonitor.com/pdc/index.php/Main/StirredReactor
@Matt-lc6bs
@Matt-lc6bs 4 жыл бұрын
Hello Sir, thank you for this fantastic tutorial. Just one thing I am really struggling to understand, what is meant by states shown at 27:39 , is it to do with state space form or something else? What confuses me is what is meant by Ca = x[0] and T = x[1] ? I would be grateful for your reply!
@apm
@apm 4 жыл бұрын
The states are the variables that show up at differential terms in the equations. Here is more information on state space: apmonitor.com/pdc/index.php/Main/StateSpaceModel (it may confuse you more, however).
@Matt-lc6bs
@Matt-lc6bs 4 жыл бұрын
​@@apm Thank you for the prompt response Sir. I have a follow up question, if I run the source code attached in the link of your description, and I print the values of Ca inside the mixer function just after the line Ca = x[0], they are different compared to when I print them after Ca = odeint is solved. What is the difference between the values of Ca stored in array x[0] compared to the Ca values that you solve for using odeint?
@apm
@apm 4 жыл бұрын
@@Matt-lc6bs the values inside the function depend on what the ODEINT solver is requesting to solve the equations. It is after the solution is completed that you can use the values.
@apm
@apm 4 жыл бұрын
Here are some additional tutorials on ODEs: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
@Matt-lc6bs
@Matt-lc6bs 4 жыл бұрын
@@apm Thank you very much Sir, your tutorials are excellent and appreciated by many of us!
@vengdasankumaresan9186
@vengdasankumaresan9186 2 жыл бұрын
Hye, excellent video. May i know how to do life ploting using odeint. Usually people doing life ploting graph using already existing datas and values.
@apm
@apm 2 жыл бұрын
Here is an example: apmonitor.com/pdc/index.php/Main/ArduinoTemperatureControl There are other examples at apmonitor.com/pdc as well.
@parthasarathisubramanian2539
@parthasarathisubramanian2539 4 жыл бұрын
Could you upload any video for partial differential equations (Diffusion).
@apm
@apm 4 жыл бұрын
Here are examples of hyperbolic and parabolic PDE solutions in Python: apmonitor.com/do/index.php/Main/PartialDifferentialEquations
@parthasarathisubramanian2539
@parthasarathisubramanian2539 4 жыл бұрын
@@apm Many thanks Prof.
@망망이탕
@망망이탕 2 жыл бұрын
Thank you for wonderful lecture! I wonder what if can solve ODEs which is q(coefficient) is function for example function of temperature and there are equation for temperature too
@mrad_uofa
@mrad_uofa 6 жыл бұрын
Very helpful! Thank you so much.
@pasha92
@pasha92 5 жыл бұрын
Nice video for beginners
@LeVi-fn6pl
@LeVi-fn6pl 5 жыл бұрын
Thank you, this really helps for me
@erkinjuraev5318
@erkinjuraev5318 4 жыл бұрын
Dear Professor, Thanks for your lessons. I couldn't find the links that you have given here, I think the site was changed.
@apm
@apm 4 жыл бұрын
The URL for the example problem is accessible from a new Card at 00:12. I also put the link in the video description: apmonitor.com/pdc/index.php/Main/TankBlending If you are looking for information on how to download Python, there are tutorials here: apmonitor.com/pdc/index.php/Main/InstallPython
@erkinjuraev5318
@erkinjuraev5318 4 жыл бұрын
@@apm Thank you!
@rw0311
@rw0311 6 жыл бұрын
Saludos desde México.
@alokray9136
@alokray9136 4 жыл бұрын
how to solve non-linear differential equation in python?
@apm
@apm 4 жыл бұрын
Here are several example problems: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations If you have a large-scale system of nonlinear differential equations then I recommend Python Gekko.
@zackm6814
@zackm6814 3 жыл бұрын
Good explanation l want to try get similar results
@barost2010
@barost2010 8 жыл бұрын
hello, I am from Germany and a great fan of your videos and I want to ask you, wether it is possible to make a modeling and simulation video about an engineering application where the fluid momentum balance equation have to be applied. Another very interesting problem to model and simulate, would be a simple hydraulic transmission system/ pump, hydraulic circuit, motor, where the hydraulic resistance, inductance and capacitance is present. And could you show an example how you can solve optimization problems without the apm solver, in python and matlab great channel, thanks for all your videos and the teaching of this interesting topics
@apm
@apm 8 жыл бұрын
Those are great suggestions!
@apm
@apm 8 жыл бұрын
Here is one video that shows a network of pipes (kzbin.info/www/bejne/j2i8c4OnfLClb7s) and solving for the fluid flow. A 2nd example is posted here: apmonitor.com/pdc/index.php/Main/FirstOrderOptimization as an example of how to use scipy.optimize.minimize - I'm currently teaching Process Dynamics and Control this semester so I'll likely have more on related topics. Thanks again for the suggestions.
@barost2010
@barost2010 8 жыл бұрын
Thanks for the answer and making references to the respective videos. I am very pleased, that my suggestions were noted, but I know of course that there have to be time for such additional topics besides the traditional lecture and your work. So if something of my suggestions would be eventually realized, it would be great:) I know that your work has a strong chemical/ process engineering background and control theory is maybe more a means to an end, but if you have experiences in Nonlinear control and Robust Control and its applications in engineering and of course within the context of Matlab and python, that would be great. Suggestions for the future:) - state feedback linearization/ input output linearization - Lyapunov based controller design - lure system, if you ever heard from that - Robust control (H_Infinity, Norms at all for controller design, Weighting transfer functions…) - Sliding Mode Control - Describing Functions - LQR, LQG, Kalman filter - Differential Geometry and its applications in Control Theory,Lie derivative/ brackets, Dynamical Systems on Manifolds/ for all this points, I not only want to learn the methodology(I learned about it in university, more than a less) I want to get an Intuition, a feeling how and why it works. This is my intention for all I am learning and it also should the intention of the teachers, I think Thanks for all your work and giving people the chance to learn this cool engineering stuff. and Excuse my english…
@ministerdixon
@ministerdixon 6 жыл бұрын
Hello! I admire your time spent demonstrating the use of Python for application programming. Wonderful stuff! Do you have any examples with State Space differential equation with feedback??? For example, dotx = Ax + Bu y = Cx +Du for u = U_ref - Kx. K = const. Could Python be used to iterate x through Newton's method (Jacobian Matrix) with saved results?
@gemmfdz6116
@gemmfdz6116 5 жыл бұрын
apmonitor.com/pdc/index.php/Main/StateSpaceModel
@JR-iu8yl
@JR-iu8yl 5 жыл бұрын
@@gemmfdz6116 Thank you
@tarciomalcher7273
@tarciomalcher7273 6 жыл бұрын
Could you please make a video on th finite difference method? i'm having a lot of trouble implementing it for laplace's equation
@apm
@apm 6 жыл бұрын
Here are 3 methods. I think you need Method 2 for the finite difference method. apmonitor.com/che263/index.php/Main/PythonDynamicSim
@rw0311
@rw0311 6 жыл бұрын
Gracias infinitas gracias.
@ilredeldeserto
@ilredeldeserto 5 жыл бұрын
amazing man!
Simulate Coupled Differential Equations in Python
28:23
APMonitor.com
Рет қаралды 51 М.
Python 🐍 Solve 4 ODEs
16:56
APMonitor.com
Рет қаралды 19 М.
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
How to Solve Differential Equations in PYTHON
23:37
Mr. P Solver
Рет қаралды 114 М.
Solving Systems Of Equations Using Sympy And Numpy (Python)
15:23
Andrew Dotson
Рет қаралды 78 М.
SciPy Tutorial: For Physicists, Engineers, and Mathematicians
1:33:29
Mr. P Solver
Рет қаралды 160 М.
Chemical Reaction Differential Equations in Python
20:34
APMonitor.com
Рет қаралды 53 М.
Best Ways to Use Gemini 2.0 (over ChatGPT & Perplexity)!
16:06
Grace Leung
Рет қаралды 23 М.
How to Solve Coupled Differential Equations ODEs in Python
10:12
Vincent Stevenson
Рет қаралды 54 М.
Symbolic Manipulation in Python
28:18
APMonitor.com
Рет қаралды 63 М.
Solving the Heat Diffusion Equation (1D PDE) in Python
25:42
Kody Powell
Рет қаралды 74 М.
Solve Differential Equations in Python
28:51
APMonitor.com
Рет қаралды 210 М.
Beginner's Guide to PID Control
29:16
APMonitor.com
Рет қаралды 48 М.