No video

Simulate Coupled Differential Equations in Python

  Рет қаралды 51,034

APMonitor.com

APMonitor.com

Күн бұрын

Пікірлер: 70
@Invisible__Woman
@Invisible__Woman 6 жыл бұрын
I almost lost my patience while looking at some examples of couple differential equations. Thank you for your amazing tutorials.
@apm
@apm 6 жыл бұрын
Thanks!
@MrNevermorefu
@MrNevermorefu 4 жыл бұрын
Great tutorial! Helped me figure out how to solve ODEs like Matlabs's ODE45.
@manuel56354
@manuel56354 4 жыл бұрын
I tried solving it with Gekko but I'm getting a "Solution Not Found" error. May you suggest me what could I tweak please? years = 15 resolution = 10 m = GEKKO() m.time = np.linspace(0, years, years * resolution + 1) H = m.Var(1e6) I = m.Var(0) V = m.Var(100) kr1 = m.Param(1e5) # new healthy cells per year kr2 = m.Param(0.1) # death rate of healthy cells kr3 = m.Param(2e-7) # healthy cells converting to infected cells kr4 = m.Param(0.5) # death rate of infected cells kr5 = m.Param(5) # death rate of virus kr6 = m.Param(100) # production of virus by infected cells m.Equation(H.dt() == kr1 - kr2 * H - kr3 * H * V) m.Equation(I.dt() == kr3 * H * V - kr4 * I) m.Equation(V.dt() == -kr3 * H * V - kr5 * V + kr6 * I) m.options.IMODE = 4 m.options.NODES = 3 m.solve()
@apm
@apm 4 жыл бұрын
You may need to apply some initialization strategies as discussed here: apmonitor.com/do/index.php/Main/ModelInitialization There is also a solution in Gekko at the bottom.
@manuel56354
@manuel56354 4 жыл бұрын
@@apm Thank you!
@kaustuvray5066
@kaustuvray5066 2 жыл бұрын
This is such a great video. I was so confused what to do in my project. Thanks a lot!!!
@mathematicslessonsandtutor8006
@mathematicslessonsandtutor8006 Жыл бұрын
Amazing video, thank you. Please any link to watch a videa where you explain how to format the style of the lines and also make a key for the various lines? Thank you
@apm
@apm Жыл бұрын
This Jupyter notebook and video solution should help with that: apmonitor.com/pds/notebooks/04_visualize.html
@chrisogonas
@chrisogonas Жыл бұрын
That was well illustrated and explained. Thanks
@SuperNova993
@SuperNova993 4 жыл бұрын
Very helpful! I have a question, is this method useful for second-order ODEs?
@apm
@apm 4 жыл бұрын
Yes. Here is an example: apmonitor.com/wiki/index.php/Apps/2ndOrderDifferential
@anandamoymukhopadhyay5158
@anandamoymukhopadhyay5158 2 жыл бұрын
Suppose we have two parameters whose initial values are known. Now if these parameters changes then what to do?
@apm
@apm 2 жыл бұрын
If they change to new values then you could just resimulate with the new values. If they need to be optimized then I recommend using a solver such as Gekko: apmonitor.com/do
@MademoiselleNettie
@MademoiselleNettie 6 жыл бұрын
You literally just saved my life! Thank you so much, now I understand what I have to do with my project!
@basic-games621
@basic-games621 4 жыл бұрын
how do you do it if there is three more pramaters like if dhdt < L then dhdt/dt
@apm
@apm 4 жыл бұрын
You can put those conditions in your model function. You can also see how to integrate in steps as shown in example 4 here: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations If you integrate in a steps (in a for loop) then you can check when the tank is empty and stop the integration.
@myblog871
@myblog871 3 жыл бұрын
Thank you so much Sir
@thedanyboyftw
@thedanyboyftw 5 жыл бұрын
Thank you so much for this! You explain this in such an understandable way.
@madduxcamden8530
@madduxcamden8530 3 жыл бұрын
You probably dont care but if you are stoned like me during the covid times you can watch pretty much all of the new movies and series on Instaflixxer. I've been watching with my brother these days =)
@reneharrison1581
@reneharrison1581 3 жыл бұрын
@Maddux Camden Yup, I have been using instaflixxer for months myself =)
@peymanfahimi6497
@peymanfahimi6497 2 жыл бұрын
Thanks a lot for your great videos. Do you have any videos on partial differential equations (PDEs) with python?
@apm
@apm 2 жыл бұрын
Here is content on PDEs: apmonitor.com/do/index.php/Main/PartialDifferentialEquations
@peymanfahimi6497
@peymanfahimi6497 2 жыл бұрын
@@apm excellent! Thanks.
@johandiaztovar4097
@johandiaztovar4097 2 жыл бұрын
What a great video!!! I have a question, how can I face the problem where one of my constants, for example, kr1 depends on the path "z", and I already know the function: kr1 = kr1_0*exp(-k*z). The best way to solve it, is making a for before define the function?
@apm
@apm 2 жыл бұрын
That requires a differential algebraic equation solver such as Gekko: apmonitor.com/pdc/index.php/Main/PythonDifferentialEquations
@ABHINAN160898
@ABHINAN160898 4 жыл бұрын
Can you put a video explaining how to make a dynamical model of a PMDC motor on Python, where user can define how the Voltage is being applied? [ Actually in my system, i have a pedelec, and i want to control the motor based on the force applied by the cyclist on the pedal. So i want to model this system, with motor,cyclist input, and torque load on motor. How can I do so? I have the diff equations of motor(2 , coupled), and the relation between the torque load and the cyclist input , and relation between cyclist input and Voltage applied accross the motor.. How to do this? Please help]
@apm
@apm 4 жыл бұрын
Here are tutorials on solving differential equations in Python: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations You may also want to check out the Python Gekko link if you are interested in transforming your simulation model into an estimator or predictive controller: apmonitor.com/pdc/index.php/Main/PythonDifferentialEquations
@kmlk1923
@kmlk1923 6 жыл бұрын
life saver !!!! No not really life but saved part of my life, may be 4 or 5 months :)) apreciate it. thanks.
@mathematicslessonsandtutor8006
@mathematicslessonsandtutor8006 Жыл бұрын
Thank so much for this great video Sir. Its so nicely explained. I followed this and was able to have my system simulated but when I vary my initial conditions I still get just the same plot as before. What are my missing out? Thank you once more.
@apm
@apm Жыл бұрын
Please see the 2nd example here: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
@elladakasarjyan5846
@elladakasarjyan5846 3 жыл бұрын
how do you simulate the same thing in second order?
@apm
@apm 3 жыл бұрын
Here is help on second order equations: apmonitor.com/wiki/index.php/Apps/2ndOrderDifferential
@elladakasarjyan5846
@elladakasarjyan5846 3 жыл бұрын
@@apm thank you for replying! this video is for a single 2nd order ode is there a video for 2nd order coupled odes? Or perhaps does APmonitor offer tutoring?
@vadisayamini5951
@vadisayamini5951 4 жыл бұрын
hav a small doubt .in our previous video about solving difeerential equation 4th case was also solved coupled equations but there u did integration for single time slot by using for loop and solved.when that can be solved this easy why did we solve like that previously?
@apm
@apm 4 жыл бұрын
You need to solve in a loop if the input (u) is unknown until you integrate to a certain time. It is also useful to change the input (u) every cycle of the loop such as when you are replaying historical data. Here are additional examples: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
@vadisayamini5951
@vadisayamini5951 4 жыл бұрын
@@apm thanks for reply.but we do know our input(u),whic h is 0 till a time and 2 afterwards we can simply use if t5 u=2 in the function model and solve problem directly by the way this hiv problem is solved right?whats main difference between these 2 questions that we used 2 different answers
@apm
@apm 4 жыл бұрын
@@vadisayamini5951 the loop is needed where the input changes every simulation period, such as in a PID controller. If your input only has one step then you could embed the if statement in your function. If you have 10+ input changes then it is often easier to manage it as an external input to the model. Here is an example of inputs changing every second: apmonitor.com/pdc/index.php/Main/TankLevel
@vadisayamini5951
@vadisayamini5951 4 жыл бұрын
@@apm thanku sir,the lecture was v helpful.i understood now.am trying to solve 1 problem of my course and even though i follwed all the steps told by u precisely am not getting results (its thrwoing many errors).i reached your website also checking if there is some section where i can post my doubt.is there any way that we could reach sir?
@vadisayamini5951
@vadisayamini5951 4 жыл бұрын
its showing error of The array return by func must be one-dimensional, but got ndim=2. and odeint(func, y0, t, args, Dfun, col_deriv, full_output, ml, mu, rtol, atol, tcrit, h0, hmax, hmin, ixpr, mxstep, mxhnil, mxordn, mxords, printmessg, tfirst) 242 full_output, rtol, atol, tcrit, h0, hmax, hmin, 243 ixpr, mxstep, mxhnil, mxordn, mxords, --> 244 int(bool(tfirst))) 245 if output[-1] < 0: 246 warning_msg = _msgs[output[-1]] + " Run with full_output = 1 to get quantitative information."
@sriharshakodati
@sriharshakodati 4 жыл бұрын
This is awesome! May I know how can we repeat this symbolically? The analytical solution? Thanks!!!
@apm
@apm 4 жыл бұрын
There is more information on symbolic solutions with Sympy here: github.com/APMonitor/data_science/blob/master/11.%20Differential_Equations.ipynb
@myblog871
@myblog871 3 жыл бұрын
I am trying to run the same code. But it does not work for me.
@apm
@apm 3 жыл бұрын
Try using the code here: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations You may have a typo somewhere.
@myblog871
@myblog871 3 жыл бұрын
import numpy as np ModuleNotFoundError: No module named 'numpy'
@myblog871
@myblog871 3 жыл бұрын
This is the error.
@apm
@apm 3 жыл бұрын
Try installing numpy, scipy, and matplotlib. Here is some help: apmonitor.com/pds/index.php/Main/InstallPythonPackages and apmonitor.com/che263/index.php/Main/PythonIntroduction
@myblog871
@myblog871 3 жыл бұрын
@@apm Thank you Sir.
@nischalkarki2960
@nischalkarki2960 6 жыл бұрын
How can I see the simulated value at a particular time, for example: no. of healthy cells at t=7 or say finding the exact steady state values?
@apm
@apm 6 жыл бұрын
You just need to feed in the times where you want to see the solution. Here is a tutorial with additional examples: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
@jtekmmx
@jtekmmx 6 жыл бұрын
How did you arrive with the value of 100 for the initial value of the free virus cell count? I cannot find this value in the reference book chapter.
@apm
@apm 6 жыл бұрын
The initial condition is arbitrary but will affect the solution. If you start with less then it will take more time to reach 100 and beyond.
@hosseinamini5793
@hosseinamini5793 6 жыл бұрын
Do you have any tutorials on how to create an ODE of N differential equations (let's say dydt(i)) and solve it?
@apm
@apm 6 жыл бұрын
This page apmonitor.com/pdc/index.php/Main/ModelSimulation has examples with first, second, and higher order differential equation solutions.
@nayelyvelez-cruz4785
@nayelyvelez-cruz4785 4 жыл бұрын
you're seriously the best
@apm
@apm 4 жыл бұрын
Thanks!
@haemin8759
@haemin8759 3 жыл бұрын
what a life-saving video! Thank you so much!
@interestingthingsaround4308
@interestingthingsaround4308 4 жыл бұрын
Thanks
@interestingthingsaround4308
@interestingthingsaround4308 4 жыл бұрын
Hi Thanks a lot for this , it made a lot of sense now. where can I find the optimization part on this
@apm
@apm 4 жыл бұрын
More information on optimization of differential equations is here: apmonitor.com/do The HIV example is specifically here: apmonitor.com/do/index.php/Main/EstimatorObjective
@ismaelchiamenti5901
@ismaelchiamenti5901 5 жыл бұрын
Great job!!
@hsinghal1
@hsinghal1 4 жыл бұрын
really nice
@xsw2ws891
@xsw2ws891 6 жыл бұрын
Actually, you saved my life too! Thanks a lot, and all that films are very usefull
@apm
@apm 6 жыл бұрын
I'm glad that you like the videos and they are helping.
@walacejunior3449
@walacejunior3449 3 жыл бұрын
Thanks so much!
@ABHINAN160898
@ABHINAN160898 4 жыл бұрын
source code?
@apm
@apm 4 жыл бұрын
Here is the problem statement: apmonitor.com/pdc/index.php/Main/SimulateHIV and source code help: apmonitor.com/do/index.php/Main/ModelInitialization
Python 🐍 Solve 4 ODEs
16:56
APMonitor.com
Рет қаралды 19 М.
Solve Differential Equations in Python
28:51
APMonitor.com
Рет қаралды 209 М.
КАКУЮ ДВЕРЬ ВЫБРАТЬ? 😂 #Shorts
00:45
НУБАСТЕР
Рет қаралды 3,5 МЛН
🩷🩵VS👿
00:38
ISSEI / いっせい
Рет қаралды 27 МЛН
Nurse's Mission: Bringing Joy to Young Lives #shorts
00:17
Fabiosa Stories
Рет қаралды 3,7 МЛН
How to Solve Differential Equations in PYTHON
23:37
Mr. P Solver
Рет қаралды 101 М.
Matrix Systems of Differential Equations
24:58
Steve Brunton
Рет қаралды 67 М.
How Calculus Helped Fight HIV/AIDS - Applications of Calculus in Biology
9:45
Solving PDEs with the FFT [Python]
14:56
Steve Brunton
Рет қаралды 50 М.
Monte Carlo Integration In Python For Noobs
15:32
Andrew Dotson
Рет қаралды 151 М.
Solving Differential Equations using scipy.odeint in Python!
25:10
Euler's Method in Python: Predator-Prey Example
23:42
Mike Saint-Antoine
Рет қаралды 1,7 М.
Solve Differential Equations in Python by Using odeint() SciPy Function
12:13
How computer processors run conditions and loops
17:03
Core Dumped
Рет қаралды 47 М.
КАКУЮ ДВЕРЬ ВЫБРАТЬ? 😂 #Shorts
00:45
НУБАСТЕР
Рет қаралды 3,5 МЛН