Solving ODEs using Python's scipy.solve_ivp function (ChEn 263 - Lecture 22, Part II)

Поділитися
Вставка
  • Опубліковано 5 вер 2024

КОМЕНТАРІ • 31

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

    Hi there, just want to say thank you very much for this video. I am taking a Python class I was having a lot of trouble with solving ODEs. I was just staring at my problem set and had no idea how to do systems of ODEs until I found your video. Thank you! Your lecture is very informative and easy to understand. I kinda hoped that you teach at our university lol.

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

      Glad to hear it helped! Best of luck in the rest of your course.

  • @Ignacio.Romero
    @Ignacio.Romero 3 роки тому +3

    This is life saving

  • @mathy2062
    @mathy2062 3 роки тому +3

    Thanks a lot!

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

    thanks, may Allah give you the guidance

    • @TreeSoftMatter
      @TreeSoftMatter  2 роки тому +1

      You're welcome and god bless you as well!

  • @tuliowetler2289
    @tuliowetler2289 2 роки тому +1

    Yess, thanks!!

  • @dollarbar1
    @dollarbar1 4 місяці тому

    nice blazer, man

  • @liladuran8733
    @liladuran8733 2 роки тому +1

    When I tried to use the times=np.linspace function I ran into issues because my endpoint is a decimal. What are my alternatives? Scale the problem differently so that my decile 0.3815 is 3815?

    • @TreeSoftMatter
      @TreeSoftMatter  2 роки тому +1

      Hi Lila, the linspace function can take decimals at both starting and endpoints: t = np.linspace(start, end, Npoints)
      So, for example:
      times = np.linspace(0., 0.3815, 50)
      should give you 50 linearly spaced points between 0 and 0.3815.
      What linspace cannot take is a floating point value for Npoints. That has to be an integer.

  • @deankay6680
    @deankay6680 2 роки тому +1

    Thank you very much for the tutorial, just subscribed! I want to solve a problem involving four CSTRs operating in series. Thus, y0 needs to be a 2D array (numpy.ndarray in Python) to account for the initial conditions in each CSTR. Unfortunately, solve_ivp seems to accept only 1D arrays as initial conditions (shape(n,)). Do you have a tip on how to go about this problem?

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

      Hi Dean, I'm not sure why you would need a 2D array for y0. If you have a system of differential equations, you should be able to express y0 as a n-dimensional 1d array. In this case, if you have 4 CSTRs that form a coupled system of 4 ODEs, you should be able to have a 4-dimensional array for y0. Check out the videos and notes here: www.et.byu.edu/~treedoug/_pages/teaching/ChEn263/Lectures/Lec22.html for more details about how to do this.

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

      As an addendum, I had the thought that maybe you have multiple concentrations in each CSTR. This would mean that if you have (for example) two concentrations in each, you would have 8 coupled ODEs. In this case you can make an 8-dimensional array for y0. y0[0] = c1 in CSTR 1 and y0[1] = c2 in CSTR 1, y0[2] = c1 in CSTR 2, and so forth.

    • @deankay6680
      @deankay6680 2 роки тому +1

      ​@@TreeSoftMatter That's exactly my case sir, excuse me for not stating it properly. Thank you for your suggestion. The 4 CSTR problem tries to model a biological system, so unfortunately there are over 60 species (i.e., over 60 individual concentrations in each CSTR). This would make it a bit tedious to create the multidimensional array for y0, but it appears this is the only way. Thank you once again for taking the time to answer and keep up your great work!

  • @konstantinosgiannokostas3655
    @konstantinosgiannokostas3655 2 роки тому +1

    How can we introduce also algebraic equations along with ODEs?

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

      I have videos on that! Here is one on linear algebraic equations:ua-cam.com/video/8X0SHplJRCg/v-deo.html, and here is one on nonlinear equations: ua-cam.com/video/paGJSaR4kcM/v-deo.html

  • @noahgraber9339
    @noahgraber9339 4 місяці тому

    How would you do this with a state space model?

    • @TreeSoftMatter
      @TreeSoftMatter  4 місяці тому +1

      I think you're going to have to be more specific with your question. Most of the time the "state space" models that I am familiar with are still ODEs (say in time), but the time ends up being implicit in the final analysis. So for example, you might have x_dot(t) = f(x, y, t) and y_dot(t) = g(x, y, t). Then you solve it for x(t) and y(t), but you are only interested in plots of y(x). This would be straightforward using the methods I outline in the video. I would need a more specific question to give a more detailed answer than this.

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

    Sir, please solve the following set of equations:
    drdt = x
    dxdt = r*(y**2 + (z+Ω)**2 * sin(θ)**2 - β*z*sin(θ)*B_θ)
    dθdt = y
    dydt = (-2*x*y-r*(z+Ω)**2*sin(θ)*cos(θ)+β*r*z*sin(θ)*B_r)/r
    dϕdt = z
    dzdt = (-2*x*(z+Ω)*sin(θ)-2*r*y*(z+Ω)*cos(θ)+β*(x*B_θ-r*y*B_r))/(r*sin(θ))
    with constants
    Ω=9.74e-3
    B_θ=-8.6e-6*sin(θ)
    B_r=25893.2e-9*cos(θ)
    β=-9.36e-10
    initial conditions
    r0 = 0.7e+8
    θ0 = 0.5*pi
    ϕ0 = 0
    x0 = 0
    y0 = 0
    z0 = 0

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

      Hi Peter, Unfortunately I don't have time to give this kind of help on UA-cam, as I am busy with classes, research, and administrative tasks. However, this should be pretty straightforward if you follow the examples given here: www.et.byu.edu/~treedoug/_pages/teaching/ChEn263/Lectures/Lec22.html. If you have a more specific question, please do ask.

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

      @@TreeSoftMatter Thank you for the videos anyway. If you would includes as one of your solved examples it would be very helpful for learners like me.

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

      @@lunthangify This example shows systems: www.et.byu.edu/~treedoug/_pages/teaching/ChEn263/Lectures/Lec22-Ex-Systems_of_ODEs.py. Your system of equations is very similar to example (C).

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

      @@TreeSoftMatter sir, I follwed exactly but no output/result. It says local variable 'times is assigned to but never used (line 40). Please have a look at the code when you have time. drive.google.com/file/d/143LHVglKq6root-PSLUS2o6egoP10mhB/view?usp=sharing

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

    Thanks so much!