Simulate Coupled Differential Equations in Python

Поделиться
HTML-код
  • Опубликовано: 1 авг 2024
  • This simulation predicts the spread of HIV infection in a body with an initial infection. The human immunodeficiency virus (HIV) infection spreads and can develop into acquired immunodeficiency syndrome (AIDS). AIDS can lead to immune system failure and eventual inability to defend the body against infection or cancer. Without treatment with antiretroviral drugs, survival time after infection with HIV is about 9 to 11 years, depending on a number of factors. Antiretroviral drugs such as TDF (tenofovir), either 3TC (lamivudine) or FTC (emtricitabine), and EFV (efavirenz) are recommended by the World Health Organization as soon as HIV infection is diagnosed. Note: The English plural of virus is viruses, not viri. See apmonitor.com/pdc/index.php/Ma... for more information on this problem.
  • НаукаНаука

Комментарии • 70

  • @Invisible__Woman
    @Invisible__Woman 6 лет назад +8

    I almost lost my patience while looking at some examples of couple differential equations. Thank you for your amazing tutorials.

    • @apm
      @apm  6 лет назад +1

      Thanks!

  • @MrNevermorefu
    @MrNevermorefu 4 года назад +5

    Great tutorial! Helped me figure out how to solve ODEs like Matlabs's ODE45.

  • @kaustuvray5066
    @kaustuvray5066 2 года назад +2

    This is such a great video. I was so confused what to do in my project.
    Thanks a lot!!!

  • @chrisogonas
    @chrisogonas Год назад +1

    That was well illustrated and explained. Thanks

  • @kmlk1923
    @kmlk1923 6 лет назад +2

    life saver !!!!
    No not really life but saved part of my life, may be 4 or 5 months :)) apreciate it. thanks.

  • @MademoiselleNettie
    @MademoiselleNettie 6 лет назад +8

    You literally just saved my life! Thank you so much, now I understand what I have to do with my project!

  • @thedanyboyftw
    @thedanyboyftw 5 лет назад +3

    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 =)

  • @ismaelchiamenti5901
    @ismaelchiamenti5901 5 лет назад +1

    Great job!!

  • @SuperNova993
    @SuperNova993 4 года назад +3

    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

  • @mathematicslessonsandtutor8006
    @mathematicslessonsandtutor8006 Год назад +1

    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

  • @myblog871
    @myblog871 3 года назад +1

    Thank you so much Sir

  • @peymanfahimi6497
    @peymanfahimi6497 2 года назад +1

    Thanks a lot for your great videos. Do you have any videos on partial differential equations (PDEs) with python?

    • @apm
      @apm  2 года назад +2

      Here is content on PDEs: apmonitor.com/do/index.php/Main/PartialDifferentialEquations

    • @peymanfahimi6497
      @peymanfahimi6497 2 года назад

      @@apm excellent! Thanks.

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

  • @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 лет назад +2

      This page apmonitor.com/pdc/index.php/Main/ModelSimulation has examples with first, second, and higher order differential equation solutions.

  • @johandiaztovar4097
    @johandiaztovar4097 2 года назад +1

    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

  • @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 лет назад +1

      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.

  • @mathematicslessonsandtutor8006
    @mathematicslessonsandtutor8006 Год назад +1

    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

  • @ABHINAN160898
    @ABHINAN160898 4 года назад +1

    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 года назад +1

      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

  • @nayelyvelez-cruz4785
    @nayelyvelez-cruz4785 4 года назад +1

    you're seriously the best

    • @apm
      @apm  4 года назад

      Thanks!

  • @basic-games621
    @basic-games621 4 года назад +1

    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.

  • @sriharshakodati
    @sriharshakodati 4 года назад +2

    This is awesome! May I know how can we repeat this symbolically? The analytical solution?
    Thanks!!!

    • @apm
      @apm  4 года назад +1

      There is more information on symbolic solutions with Sympy here: github.com/APMonitor/data_science/blob/master/11.%20Differential_Equations.ipynb

  • @manuel56354
    @manuel56354 4 года назад +3

    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 года назад +1

      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!

  • @interestingthingsaround4308
    @interestingthingsaround4308 4 года назад +1

    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

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

  • @anandamoymukhopadhyay5158
    @anandamoymukhopadhyay5158 2 года назад +1

    Suppose we have two parameters whose initial values are known. Now if these parameters changes then what to do?

    • @apm
      @apm  2 года назад +1

      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

  • @hsinghal1
    @hsinghal1 4 года назад +1

    really nice

  • @interestingthingsaround4308
    @interestingthingsaround4308 4 года назад +1

    Thanks

  • @vadisayamini5951
    @vadisayamini5951 4 года назад +1

    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 года назад +1

      @@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 года назад +1

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

  • @elladakasarjyan5846
    @elladakasarjyan5846 3 года назад +1

    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?

  • @haemin8759
    @haemin8759 3 года назад +2

    what a life-saving video! Thank you so much!

  • @myblog871
    @myblog871 3 года назад +1

    I am trying to run the same code. But it does not work for me.

    • @apm
      @apm  3 года назад +1

      Try using the code here: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations You may have a typo somewhere.

    • @myblog871
      @myblog871 3 года назад +1

      import numpy as np
      ModuleNotFoundError: No module named 'numpy'

    • @myblog871
      @myblog871 3 года назад +1

      This is the error.

    • @apm
      @apm  3 года назад +1

      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.

  • @ABHINAN160898
    @ABHINAN160898 4 года назад

    source code?

    • @apm
      @apm  4 года назад +1

      Here is the problem statement: apmonitor.com/pdc/index.php/Main/SimulateHIV and source code help: apmonitor.com/do/index.php/Main/ModelInitialization