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

  Рет қаралды 23,671

Tree Soft Matter Theory

Tree Soft Matter Theory

4 жыл бұрын

This video contains part II of a lecture for Chemical Engineering 263 (Undergraduate Numerical Tools) at Brigham Young University. In the lecture, I discuss examples of:
(1) How to solve single ODEs using the scipy.solve_ivp function in Python
(2) How to solve systems of ODEs using scipy.solve_ivp, and
(3) How to solve higher order ODEs using scipy.solve_ivp.
Part I of this video ( • Systems of ODEs (ChEn ... ) discusses systems of ODEs, their standard format, and how to turn a higher order ODE into a system of first order ODEs.
More resources related to this lecture can be found at: www.et.byu.edu/~treedoug/teac...

Пікірлер: 31
@aquilar1943
@aquilar1943 2 жыл бұрын
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.
@mathy2062
@mathy2062 3 жыл бұрын
Thanks a lot!
@TreeSoftMatter
@TreeSoftMatter 3 жыл бұрын
You're welcome!
@Ignacio.Romero
@Ignacio.Romero 3 жыл бұрын
This is life saving
@TreeSoftMatter
@TreeSoftMatter 3 жыл бұрын
Glad it was helpful!
@mathy2062
@mathy2062 3 жыл бұрын
Tarea numérica-fcfm? Xd
@Ignacio.Romero
@Ignacio.Romero 3 жыл бұрын
@@mathy2062 Jaja si xd
@ralphjuliussulitvelasquez5529
@ralphjuliussulitvelasquez5529 2 жыл бұрын
Thanks so much!
@TreeSoftMatter
@TreeSoftMatter 2 жыл бұрын
You're welcome!
@tuliowetler2289
@tuliowetler2289 2 жыл бұрын
Yess, thanks!!
@TreeSoftMatter
@TreeSoftMatter 2 жыл бұрын
You're welcome!
@alberthema
@alberthema 2 жыл бұрын
thanks, may Allah give you the guidance
@TreeSoftMatter
@TreeSoftMatter 2 жыл бұрын
You're welcome and god bless you as well!
@liladuran8733
@liladuran8733 2 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
​@@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!
@dollarbar1
@dollarbar1 Ай бұрын
nice blazer, man
@konstantinosgiannokostas3655
@konstantinosgiannokostas3655 2 жыл бұрын
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:kzbin.info/www/bejne/bomThHumoa-Feck, and here is one on nonlinear equations: kzbin.info/www/bejne/ppKqe4aXh5mema8
@noahgraber9339
@noahgraber9339 2 ай бұрын
How would you do this with a state space model?
@TreeSoftMatter
@TreeSoftMatter 2 ай бұрын
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 Жыл бұрын
Hi Peter, Unfortunately I don't have time to give this kind of help on KZbin, 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 Жыл бұрын
@@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
Integrating Excel and Python Using XLWings (ChEn 263 - Lecture 23, Part II)
10:43
How to Solve Differential Equations in PYTHON
23:37
Mr. P Solver
Рет қаралды 97 М.
1❤️#thankyou #shorts
00:21
あみか部
Рет қаралды 88 МЛН
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 20 МЛН
Tom & Jerry !! 😂😂
00:59
Tibo InShape
Рет қаралды 56 МЛН
Using scipy integrate solve ivp
9:05
Physics With Nero
Рет қаралды 23 М.
Solving ODEs using Python Scipy
17:33
ignite.byu.edu
Рет қаралды 7 М.
SHA: Secure Hashing Algorithm - Computerphile
10:21
Computerphile
Рет қаралды 1,2 МЛН
How to: Solve an ODE in Python (Boundary Value Problem)
48:35
Coding a Fourth-Order Runge-Kutta Integrator in Python and Matlab
36:52
Do you ACTUALLY NEED math for Machine Learning?
0:51
Nicholas Renotte
Рет қаралды 130 М.
Solving Differential Equations using scipy.odeint in Python!
25:10
1❤️#thankyou #shorts
00:21
あみか部
Рет қаралды 88 МЛН