Solving Differential Equations In Python In Less Than 5 Minutes (General Solution)

Поділитися
Вставка
  • Опубліковано 14 чер 2018
  • In this video I show you how to solve for the general solution to a differential equation using the sympy module in python.
  • Розваги

КОМЕНТАРІ • 115

  • @SmajdalfFrogi12
    @SmajdalfFrogi12 5 років тому +50

    Andrew: "equation function"
    Classes: am I a joke to you?

  • @quahntasy
    @quahntasy 6 років тому +34

    I love these coding videos.Keep it up!

  • @starship1701
    @starship1701 6 років тому +4

    Cool! I like how simple it is.
    What resource(s) did you use to learn how to code in python, just in general?

  • @mattRRgraham1996
    @mattRRgraham1996 6 років тому +35

    While I didn't use python for it, I used Matlab to solve for some interesting nonlinear differential equations in my Nonlinear Dynamics and Chaos Theory class. I used Matlab to play with the Lorenz equations and reproduce his results in his original paper which was SUPER cool. I'd be happy to send you my code if you'd want. That was probably my favorite thing I did in the class. Idk if I still have it or not, but there was also a general relativity equation that I used Matlab to help solve because it wasn't immediately obvious to me what to do on paper for the homework assignment, so I tried using Matlab instead. I love these Coding videos and hearing about what's going on with you and grad school, research internship, etc., it's inspiring! Keep up the good work man! I love this channel. It's a gem amongst the sea of youtubers. I'll be applying to math grad school this upcoming fall so it's nice to see somebody in similar shoes a bit further down the road from me.

    • @abhaspradhan1459
      @abhaspradhan1459 4 роки тому

      I am actually planning to solve the Lorenz equations too and that's why I'm here!

    • @amangangwar2535
      @amangangwar2535 4 роки тому

      how to solve nonlinear second order diff eqq Matlab or python?

    • @bilalhussein9730
      @bilalhussein9730 3 роки тому

      @@amangangwar2535 I prefer Mathematica for DEs: reference.wolfram.com/language/tutorial/DSolveOrdinaryDifferentialEquations.html#6538.
      Matlab works fine too: www.mathworks.com/help/symbolic/solve-a-single-differential-equation.html#:~:text=Represent%20the%20derivative%20by%20creating,Solve%20ode%20for%20y%20 though.

    • @leonardocabrera9253
      @leonardocabrera9253 2 роки тому +3

      Python is free so Matlab is not an alternative for non students.

    • @temiladeadeniran7811
      @temiladeadeniran7811 Місяць тому

      Can I see your code ? …. The one you used to solve Lorenz equations

  • @AstroRoxy
    @AstroRoxy 6 років тому +2

    I'm too jus getting started in python, somewhere in the loops section, even though I didn't understood how u got the end result, I hav did the exact same in paper, looking forward to solve using python too.
    will come here, when I do that 😎

  • @zokalyx
    @zokalyx 6 років тому +5

    also do some numerical solution to a differential equation! (preferably one with no analytical solution, such as the pendulum one, or if you can do it, some crazy thing with pendulums, atwood machines and springs using lagrangians and stuff)

  • @DanielLima-bd8sv
    @DanielLima-bd8sv 5 років тому +2

    Great videos! Helped me a lot. Could you please make a video about PDE's ? Thanks

  • @prashant.tiwariOO7
    @prashant.tiwariOO7 Рік тому

    Short , simple and clear. great

  • @amearaadan9214
    @amearaadan9214 7 місяців тому

    THANK U!! I decided to do nothing for my coding module this entire semester thinking we had no work then he throws an individual project at us worth 50% of the module due in a few days so I have to learn everything I missed rlly quick:( this helped a lot

  • @sheikhakbar2067
    @sheikhakbar2067 4 роки тому

    Excellent video, thank you very much!

  • @ashutoshsharma1640
    @ashutoshsharma1640 4 роки тому

    Thanks a lot a very helpful and nicely made crisp video

  • @Oakenhelm1
    @Oakenhelm1 5 років тому

    Nice vid, easier to follow than my class is

  • @Mark00747
    @Mark00747 5 років тому +4

    How can you solve for the constants in Python?

  • @ywk7282
    @ywk7282 2 роки тому

    Thank you fo rthe video!!:) Is there any way to put in values in x and get the output values form f? If there is it would be great to know

  • @MrZak-rf3vq
    @MrZak-rf3vq 4 роки тому +1

    This is literally magic.

  • @leonardocabrera9253
    @leonardocabrera9253 2 роки тому +2

    Hey does someone know hot to plot the solutions, and how to define initial values to find c1 and c 2?

  • @xabiergarciaandrade2656
    @xabiergarciaandrade2656 6 років тому +2

    Mmm why do you use two lines of code to import the whole sympy library instead of just typing import sympy as sp?

  • @carloswayne8640
    @carloswayne8640 2 роки тому

    Hi! I would like to know how to define a constant in the code. I ought to solve an equation with no number constants. I really liked your video

  • @oanmachi2629
    @oanmachi2629 5 років тому

    so for example, if i want to set f(0)=1 to sovle C1, C2. plz tell me how to write that?

  • @kayeassy
    @kayeassy 6 років тому

    Well can we solve for special functions as well??

  • @sauvikdas5932
    @sauvikdas5932 4 роки тому

    If I want to solve some differential eqtn containing exponential terms. What should I write?

  • @malayapaul458
    @malayapaul458 5 років тому +1

    Can you please start a series on learning python

  • @ejinduyoung5046
    @ejinduyoung5046 3 роки тому

    How do you account for initial conditions?

  • @anuragmishra6262
    @anuragmishra6262 4 роки тому

    It was really helpful

  • @Felipe-53
    @Felipe-53 4 роки тому

    good one, thanks!

  • @aishwaryadas2859
    @aishwaryadas2859 Рік тому

    Thanks for this video, can you do the same for delayed differential equation using ddeint. I want to try it for multiple delays. Can you help me out?

  • @nonamenoname2618
    @nonamenoname2618 3 роки тому

    Are there step-by-step solutions for this, like there are for Wolframalpha?

  • @loconino5498
    @loconino5498 Рік тому

    thank you so much

  • @abhisheksingh-xf8kb
    @abhisheksingh-xf8kb 3 роки тому

    How can I solve n second order coupled differential equation (Fermi pasta ulam chain)

  • @saibharath5510
    @saibharath5510 4 роки тому

    Thanks man!!!

  • @santiagobrouardmartin965
    @santiagobrouardmartin965 4 роки тому +1

    Thank you for the video, Andrew. I tried to solve something like {dy/dt +b*x+a*y= 0, dx/dt- b*y-a*x=0}, with a and b being arbitrary constants, and get into trouble with dsolve. Could you help me with that, please?

  • @miltonincsw
    @miltonincsw 4 роки тому +3

    Ryan Reynolds teaching python, can life get better than this

  • @yinyl
    @yinyl 3 роки тому

    cool video~ Thanks

  • @begatbegat7273
    @begatbegat7273 5 років тому

    thank you!

  • @sayansagar6868
    @sayansagar6868 4 роки тому

    Hello Andrew why are you used "printing, latex=true" statement here. I can't understand the 2 nd line of programming. Explain me brother

  • @ahmadalghooneh2105
    @ahmadalghooneh2105 4 роки тому

    Dear andrew, people are mostly interested in numerical solvers, do you have a video about that?

  • @LeMon-ss3us
    @LeMon-ss3us Рік тому

    How can i write cos and sin in this code cuz i have trying and it appears a error named cant convert expresstion to float

  • @mrinalrajak5526
    @mrinalrajak5526 5 років тому

    Thank you Sir....

  • @mther123
    @mther123 5 років тому

    Great

  • @googlegoogle1610
    @googlegoogle1610 2 роки тому

    Please, can you teach us how to solve the finite difference method in python?

  • @ruffnck4637
    @ruffnck4637 4 роки тому +1

    What about the system of equations?

  • @thed_motivation4897
    @thed_motivation4897 Рік тому +1

    I love the video. But, I am using Python 3.11.4 and it isn't running this particular code. I am using window 11, please do recommend site to check for download for this to work. Can this work for fourth differential equation

  • @abhisheksingh-xf8kb
    @abhisheksingh-xf8kb 3 роки тому

    Sir, I want to use solution of differential Equation in other code of python how can I do this.

  • @jacobkammer2843
    @jacobkammer2843 4 роки тому

    what does * signify in the third line of code where your are importing sympy?

    • @jacobkammer2843
      @jacobkammer2843 4 роки тому +1

      @@AbhishekSharmaabolt9 Thanks. I had never seen that in the past so thought it was strange and now I know not recommended. thanks a bunch

  • @engineering_chaos2749
    @engineering_chaos2749 3 роки тому

    Love this

  • @rickandelon9374
    @rickandelon9374 5 років тому

    Andrew, Can I ask you why are you not using Mathematica?

  • @hakulab920
    @hakulab920 2 роки тому

    why did you write both "from sympy import *" and "import sympy as sp" ? Can I use import sympy as sp only?

  • @unknown360ful
    @unknown360ful 6 років тому

    Hey Andrew! Nice vid! But just wondering, why do you call that format 'LATECH', isn't it LATEX? As in Latex the material?

    • @unknown360ful
      @unknown360ful 6 років тому

      Thanks! It really was helpful! I had no clue! I always thought it was LATEX as in the material...

    • @heyredwhale
      @heyredwhale 6 років тому +2

      Actually that is just partially true. TeX, the typesetting sytem LaTeX is build on, is an abbreviation for the Greek "techne", so the letters are actually the Greek letters tau epsilon chi. Chi is pronounced differently than the English X and it is there the pronunciation of TeX comes from.

    • @carlosvargas2907
      @carlosvargas2907 6 років тому

      Don't care. I'll say LAHTEKS

  • @VishalSingh-zs5tr
    @VishalSingh-zs5tr 3 роки тому

    Sir can u show how to solve fourth order differential equation in two variables x,y

  • @TheNewPhysics
    @TheNewPhysics 2 роки тому

    What about nonlinear differential equations?

  • @lisaroy.588
    @lisaroy.588 Рік тому

    Cool

  • @nurudeennajeem6605
    @nurudeennajeem6605 6 місяців тому

    Thanks

  • @shamsnoor7043
    @shamsnoor7043 4 роки тому +5

    Eq(-5*f(x) + Derivative(f(x), (x, 2)), 0)
    This keeps appearing as my output instead of the clear d/dx form your output takes. Could you please point out what I'm doing wrong?

    • @tonynguyen8166
      @tonynguyen8166 4 роки тому +2

      Im late to this but what did u use print instead of display? print just prints out what u wrote display shows the function in the correct form.

    • @shamsnoor7043
      @shamsnoor7043 4 роки тому +1

      @@tonynguyen8166 Apparently I was missing a map file when I was using Pycharm. I started using Jupyter later on and the program itself prompted me to download the missing file. The issue got fixed by that.

    • @tonynguyen8166
      @tonynguyen8166 4 роки тому +1

      @@shamsnoor7043 That also makes sense the program shouldnt run if you don't have the package for it. Just out of curiosity why were u using pycharm? I only use notebook since it has most of the packages i need and it's easier to read and view.

    • @piyomaru479
      @piyomaru479 4 роки тому

      I used python application and we're having the same result. I don't know how to fix it. 😭

    • @tonynguyen8166
      @tonynguyen8166 4 роки тому +1

      @@piyomaru479 if you are using python instead of juypter u r gonna have to download the sympy package

  • @NTC
    @NTC 2 роки тому

    you're smart! :D

  • @Israel220500
    @Israel220500 5 років тому +1

    Why bother importing sympy as sp if you already polluted the namespace?

  • @elafmoataz6051
    @elafmoataz6051 4 роки тому

    Can you please help me solving this non linear second ODE. i^2 = (m/Kt) * X'' + (K/Kt) X? TIA.

  • @raulrios5748
    @raulrios5748 3 роки тому +1

    I need to get the c1 and c2 values, how can I do that?, I already have the initial conditions.

    • @sayanjitb
      @sayanjitb 3 роки тому

      Just insert initial conditions into the solution and solve for c1 and c2

    • @dracula2227
      @dracula2227 3 роки тому

      @@sayanjitb how do we do that?

    • @sayanjitb
      @sayanjitb 3 роки тому

      @@dracula2227general solution of a second-order diff equation contains two arbitrary constants, and in order to fix those just insert two initial values or boundary values that are already provided to you.

  • @khanrabbi5465
    @khanrabbi5465 5 років тому +1

    Hello Andrew. Thank you for your wonderful video. I want to know how I can use Python to solve 3rd order non-linear homogenous ODE like below:
    d3y/dx3 = (dy/dx)^2 - y*(d2y/dx2)

    • @tonynguyen8166
      @tonynguyen8166 4 роки тому

      U use sympy the same as what he did all u do is adjust the equation that he wrote to urs.

  • @parzival_zd_1156
    @parzival_zd_1156 6 років тому +3

    Nice..😄😄👍👍
    I'm also Learning... Python..😅😅
    I've started before a Week.
    😆😆
    This Journey of Learning Python is Going Good...😅
    I hope I will learn All very Soon..😆😆😆😆

  • @hamidouhrir4910
    @hamidouhrir4910 3 роки тому

    Pls How to use that solution to plot. Thnks

  • @husseinalsajer4381
    @husseinalsajer4381 3 роки тому

    Hello , please how can I plot this Equations ? please

  • @AdityaKumar-ij5ok
    @AdityaKumar-ij5ok 5 років тому

    I came across this differential equation while studying damped oscillation can you please tell how to solve it?
    M x'' + B x' + K x = 0
    The derivatives of position are, of course, with respect to time.

    • @gagers78
      @gagers78 5 років тому +2

      use an auxiliary equation method. let x = e^kt and differentiate to get x' and x''. then you should get a quadratic in terms of k and the constants of the differential equation all multiplied by e^kt. You can then divide through by e^kt to get a quadratic you can solve in k.
      This gives you 2 solutions. The general solution is then x=c1e^k1t+c2e^k2t. It will look nicer when you write it out. If the values are complex it will still work just the constants c1,c2 are different. you could expand the equation out using Euler's formula to get a function in sin and cos. Alternatively if k1,k2 are complex rework the question but with x=c1sin(k1t)+c2cos(k2t) as your function to differentiate.

  • @abhinaba__saha
    @abhinaba__saha 4 роки тому

    this is magic

  • @Katabatic44
    @Katabatic44 5 років тому +7

    did you learn programming before or after starting grad school?

    • @charlesmarseille123
      @charlesmarseille123 4 роки тому +3

      the first day you ask about coding should be the first day you start. Whatever your background, skills or grades. If you can google, you can code.

  • @oulimatatall5567
    @oulimatatall5567 3 роки тому

    how to get C1?

  • @prateekyadav7679
    @prateekyadav7679 2 роки тому

    How to define f?

  • @MathPhysicsFunwithGus
    @MathPhysicsFunwithGus 3 роки тому

    please do a P.D.E video!

  • @darchcruise
    @darchcruise 5 років тому

    Hi Andrew. Do you tutor (Diff Equation) via Skype?

  • @SO-dl2pv
    @SO-dl2pv 5 років тому +1

    if you have already imported everything from sympy then why do bother yourself using sp prefix? or if you have imported sympy as sp then why you import everything from sympy!!!!!

  • @teben2622
    @teben2622 3 роки тому +1

    Is this pde or ode?

  • @chadurdy7555
    @chadurdy7555 3 роки тому

    😧🤯🧠✨😎🖤

  • @prInCeSsoFdArKiNg
    @prInCeSsoFdArKiNg 5 років тому

    OMG Thank you!!!!!!!!!!

  • @vijayyadav3673
    @vijayyadav3673 2 роки тому

    Dear Andrew can you please solve the equation
    dG/dt=G_in-f_2 (G(t))-f_3 (G(t)) f_4 (I(t-τ_2))+c
    dI/dt=f_1 (G(t-τ_1)) (k_0 I(t-τ_2))/(e^cI(t-τ_2 ) -1)-d_i (t)
    also plot plot the solution.
    thanks

  • @prateek2849
    @prateek2849 6 років тому +4

    I gave it the equation for *forced damped oscillations* and 'he' (not assuming genders, sorry feminists) solved it beautifully 👏😂

  • @fraktasticful
    @fraktasticful 4 роки тому +1

    Why is Ben Affleck teaching me python?

  • @jake_runs_the_world
    @jake_runs_the_world 6 років тому +1

    Where's your beard

  • @GojoSenpai25
    @GojoSenpai25 6 років тому +1

    Why use python when matlab can solve 2nd order dif eqs

    • @edvanbruggen550
      @edvanbruggen550 6 років тому +6

      Python is free, open source, and the standard in the scientific community

    • @GojoSenpai25
      @GojoSenpai25 6 років тому

      Ed van Bruggen however at least in engineering they care more about using matlab plus some universities have access to it for free

    • @edvanbruggen550
      @edvanbruggen550 6 років тому +1

      DocAlex yeah I true Matlab is more common in engineering circles compared to the scientific world, in my experience in research there seems to be a slow shift away from matlab. I go to a large research university and while a lot of our applied math classes are in matlab we do not get it free. From what I can tell most no physicists use matlab and it is completely unheard of in astronomy, both using mainly python, and some C++ or even fortan. While I can tell it is definitely much more common in engineering most engineerings I have worked with prefer to use python when possible.

    • @edgardparra6497
      @edgardparra6497 6 років тому +1

      If your job is to make software, then you need to do differential equations in python, C, or whatever the environment that you require. Since your asking why use python, then you're obviously not a software developer. Stick to Matlab if that's what you know.