Matlab ode45 (and Similar) Tutorial Part 1: The Basics

  Рет қаралды 49,446

Scholastic Samaritan

Scholastic Samaritan

6 жыл бұрын

Here is what one could essentially consider an introductory lecture to Matlab’s numerical ode solver (with skip links for flexibility). Don't let the length of the video scare you. There are skip links provided below to help navigate between the different portions of the video. (Note that Example 1 and the Matlab there are longer than for Example 2 since they introduce some basic info.) So if you're only popping in to see a particular section or you're already familiar with the introductory basics, don't worry. You won't have to sit through the entire video.
You will notice that this video is rather lengthy compared to the usual. This is because I wanted to go into sufficient detail to explain how Matlab's numerical ode solver works. In doing so, my hope is to enable people to understand and use the process rather than regurgitate information. I genuinely hope that this video -- and the others in this series -- will be helpful to you. Let me know what you think in the comments below.
Video Navigation (Skipping Links):
1) Basic Concepts (The very beginning of the video)
(You can just scroll back to the beginning)
[~13 min]
2) First Example Problem (Non-constant coefficients | 13:17)
[~4 min]
3) Using Matlab to Solve Problem 1 (Introduces 3 Approaches | 17:59)
[~19min ... Only ~10min if simply watching Approach 1)
4) Second Example Problem (Constant Coefficients | 37:55)
[~5min]
5) Using Matlab to Solve Problem 2 (43:45)
[~3min]
6) Quick "Pro's and Con's" (46:05)
[~2min]
I apologize for the reference to the "annotations." I'm a bit of a noob, so I wasn't aware that they got cancelled some time ago. There are still skip links in the description, at least.
I want to give my sincerest thanks to the legendary Professor Vincent Nguyen at the University of Maryland, College Park. Without his help, I would never be able to understand how to use Matlab's ode solver like I do today.

Пікірлер: 64
@kasranosratpour6450
@kasranosratpour6450 Жыл бұрын
Not one of the best; The best tutorial of ode 45 found on KZbin. Thanks 🍻🤝
@tz6615
@tz6615 4 жыл бұрын
Man, you are the hero! I have watched so many videos about this, but yours is the only one that lead me to the right direction! Thank you so much!
@iamyoyo96
@iamyoyo96 6 жыл бұрын
One of the best videos on ODE45 that I found on youtube, thanks!
@TaterBot1000
@TaterBot1000 6 жыл бұрын
Thanks for the kind words. I'm glad it was helpful!
@mousaalsaeed9410
@mousaalsaeed9410 5 жыл бұрын
thanks man, I searched the whole internet for a comprehensive and clear tutorial for ode45 and your videos are the best man like really the best
@chibuikeokekeogbu8022
@chibuikeokekeogbu8022 2 жыл бұрын
I've seen several videos but this STANDS OUT!!! Thank you
@nicolasdias6154
@nicolasdias6154 5 жыл бұрын
The best video about ode45 !!! Thank you man !
@SalymGuer
@SalymGuer 6 жыл бұрын
I have to say that this is the best video explaining the ode function ! Ty
@TaterBot1000
@TaterBot1000 6 жыл бұрын
Thanks! I'm glad it was useful!
@F1ght7
@F1ght7 5 жыл бұрын
Thank you for this phenomenal video! You’re a lifesaver! :)
@dallasdominguez2224
@dallasdominguez2224 2 жыл бұрын
Excellent explanation my friend. Thank you for taking the time to make this!
@krishnakadiyam2864
@krishnakadiyam2864 6 жыл бұрын
thanks for your marvelous efforts..i remember ur concepts for life long
@wowthatsveryawesome
@wowthatsveryawesome 3 жыл бұрын
amazing job at explaining! thanks so much
@elcamnino7
@elcamnino7 3 жыл бұрын
Do you always have to call out the function in the Command Window, or are you able to just hit 'Run' in one of the versions, or set it up such that you can hit 'Run'?
@avb20540
@avb20540 6 жыл бұрын
I got the wynaut reference haha. Good video!
@TaterBot1000
@TaterBot1000 6 жыл бұрын
Thanks! :D
@marrsbar5040
@marrsbar5040 4 жыл бұрын
How would I define a value of xdot at a certain x value as a variable???
@jyothsnabali
@jyothsnabali 6 жыл бұрын
LIFE SAVER..! thanku
@TaterBot1000
@TaterBot1000 6 жыл бұрын
My pleasure!
@danielserventi8792
@danielserventi8792 4 жыл бұрын
This man here makin pokemon references
@themistoklischronis8510
@themistoklischronis8510 4 жыл бұрын
good lecture man
@elvesun
@elvesun 2 жыл бұрын
I am very thankful to you
@shalipse
@shalipse 4 жыл бұрын
Very helpful. Thank you sir I will be grateful if you can do state space model for a thermodynamics system
@mohanmustafa
@mohanmustafa 3 жыл бұрын
Thank you so much.
@blueturkeyguitar
@blueturkeyguitar 5 жыл бұрын
Thank you, this was very helpful!
@minhthuan2132
@minhthuan2132 6 жыл бұрын
very helpful, thank a lot sir
@TaterBot1000
@TaterBot1000 6 жыл бұрын
Glad to help!
@shreyasvalake3774
@shreyasvalake3774 4 жыл бұрын
hi i'm unable to run first 2 methods in matlab 2017
@FlyingBeesQuotes2023
@FlyingBeesQuotes2023 Жыл бұрын
Really helpful video. Can you repeat the same with python ?. Which will be really beneficial for those who are doing mathematical modelling with Matlab & python.
@youssefelmahjoubi8278
@youssefelmahjoubi8278 2 жыл бұрын
thank you so much sir you help me
@jorgemercent2995
@jorgemercent2995 3 жыл бұрын
You should really go into about state vectors, it is so confusing if you skip all those!
@daniarevalo9880
@daniarevalo9880 6 жыл бұрын
Really easy to underestand, thank you. By the way, how would you add a control input to that system? would you have to add another function call ? or just write t inside the system function?
@TaterBot1000
@TaterBot1000 6 жыл бұрын
I'm glad it was helpful! When you say, "control input," are you referring to a control system or something else?
@daniarevalo9880
@daniarevalo9880 6 жыл бұрын
Scholastic Samaritan yeah, a control system and test inputs, like steps functions.
@TaterBot1000
@TaterBot1000 6 жыл бұрын
Gotcha. Yeah, if you're testing inputs into the system, you just include that function in your equation. A classic example is with vibrations problems, where you have some equation similar to mx2dot + cxdot + kx = f(t), where f(t) is some forcing function. In this case, f(t) would be the input into the system that you could control. So if I wanted to see how the system responded to a step input, I would replace f(t) with u(t). Does that answer your question?
@daniarevalo9880
@daniarevalo9880 6 жыл бұрын
I Think so, yeah, I had this doubt because I want to test a nonlinear control into a system, but this control function depends on the system's states. I will try just writing the control function into the system model.
@TaterBot1000
@TaterBot1000 6 жыл бұрын
That should be doable. I believe I've run into a similar problem before and been able to solve it.
@gyansetu8096
@gyansetu8096 4 жыл бұрын
The above-mentioned program is not running for Matlab 2018
@gyansetu8096
@gyansetu8096 4 жыл бұрын
Method 2 and 3, ran without any error but method 1 still have errors
@Knexfoof
@Knexfoof 6 жыл бұрын
But how on earth can we automate the process of converting the systems of 2nd order odes to the state variables? All examples online assume just a system of say 2 or 3 equations, and so can be done by hand Is there a way matlab can automate this process for say 40+ equations?
@TaterBot1000
@TaterBot1000 6 жыл бұрын
I'm not aware of a way for Matlab to automatically convert a system of odes into state variables before solving. I imagine that writing something to make Matlab do that would take a lot of effort. For one thing, this choice of state variable representation is only one kind of approach, called "phase-variable choice." Usually students will only be working with this kind of approach though, so I've avoided that discussion. In short, automatically converting equations to state variables would be a rather taxing and complex task for Matlab. Practically speaking, I imagine that it would be rare for a relationship to be seen between a function and its 40th derivative. Even so, it's possible to have Matlab solve this, but it requires you to get the equation in state variable form first. If you're strictly dealing with 1D systems, then setting this up by hand and chucking it into Matlab wouldn't be *too* much work anyway.
@Knexfoof
@Knexfoof 6 жыл бұрын
Scholastic Samaritan I have a large 2D 3 X 5 node frame structure with 3 dofs per node (Vertical displacement, bending moment, and along axis torsion). 2 of these dofs are removed as there's no movement in those at 1 of the nodes, hence I have a 43*43 stiffness and mass matrix
@TaterBot1000
@TaterBot1000 6 жыл бұрын
So you're talking about a literal set of equations, not some 40-th order ode
@Knexfoof
@Knexfoof 6 жыл бұрын
Scholastic Samaritan yes, I've tried using the odeToVector field, but it's generation of the X(t)s that can't be automatically done
@TaterBot1000
@TaterBot1000 6 жыл бұрын
I see. Yeah I imagine it'd be difficult to find a way for Matlab to automatically convert *any* set of odes into state space. Again, there are complications and variations in how it's done. Blah blah blah. However, many vibrations textbooks provide analytical expressions for the state space representation of a general MDOF system. They're especially eager to derive this if the MDOF system is assumed to be linear. I'm sure this could be found online as well. These representations can be obtained from knowledge of the mass matrix, damping matrix, stiffness matrix, force vector, etc. If we're strictly speaking of linear MDOF systems, you can likely find a way to use the derived expression to directly obtain a state space representation that is fed to Matlab's ode45 (or odeXY) solver. This would require you to declare the mass matrix, stiffness matrix, etc. But it'd at least alleviate some of the work. For instance, perhaps you could use some sdot = A*S + B*F, where A and B are obtained from the mass matrix, etc., etc., F is the force vector, and S is the state vector. Perhaps S could be declared as some S = [S(1); S(2); S(3); ...]. (Make sure vector S has appropriate dimensions for matrix multiplication.) Of course, you could work with non-linear MDOF systems also, but this would require even more work/complicated representations. That's just my first impression. The solution to this particular problem of yours may be slightly more complicated. But given that information, I can't imagine that it would take much effort beyond this. The main effort (if not all of it) would be put into making sure that Matlab is able to correctly see what S and sdot are. You should already know the other matrices and vectors, so they can easily be declared. If this works, there might be a way to take this a step further, where a general function is written to make Matlab obtain the state space equations from the mass matrix, etc., etc. Then the issue simplifies down to sdot = function(M,C,K,...). Again, you'll have to know the matrices. (I'm sure you know that though. Saying "You have to know the matrices" is like saying, "You'll have to know the equations that you're working with.")
@teny238
@teny238 9 ай бұрын
That Wynaut reference caught me off guard 😅
@peetkumarghosh5619
@peetkumarghosh5619 3 жыл бұрын
for those the second method is not working try this [time, state_values] = ode45(@g,[1,30],[1,0]); x = state_values(:,1); xdot = state_values(:,2); figure(1) plot(time,x) function sdot = g(t,s) % [s] = [s(1) s(2)] = [s1, s2] = [x, xdot] sdot = [s(2); (5- s(2)*sin(t) - s(1)*exp(t))/t^2]; end
@adib9818
@adib9818 2 жыл бұрын
love how tired you are
@uran4k
@uran4k 5 жыл бұрын
what's purpose of this video?)
@jorgemercent2995
@jorgemercent2995 3 жыл бұрын
could you just define what on earth are state vectors and state variables????
@Al-ju7th
@Al-ju7th 3 жыл бұрын
He literally clearly explains it, did you even watch the video?
@jorgemercent2995
@jorgemercent2995 3 жыл бұрын
@@Al-ju7th No he did not, he made passing mention. Do you have the timestamp?
@ThePseudojew
@ThePseudojew 5 жыл бұрын
He's falling off the building @for_the_views :-) See what I did there?
@ElonMuskTheOne
@ElonMuskTheOne 6 жыл бұрын
looks like a lot of acrobatics is going on here. Why can't you just put everything in one file and explain the basics?
@TaterBot1000
@TaterBot1000 6 жыл бұрын
So like I said, it's kind of like a "mini lecture" on the topic. And that's my warning in case people want to see another video with less details. The reason I made a video that goes this far in depth and has all these examples is that a lot of videos and books explain things on a surface level with the easiest example of all time...without even explaining the "why's" of their Matlab coding. A lot of people I meet know how to solve those super easy examples, but they can't handle any others -- even if they're in still in one dimension. This video explains the actual basics of the ode solver and the "why's" of the programming so that people can understand what they're actually doing and encounter less confusion in harder problems. The disadvantage of this, as you pointed out, is that a lot of detail is needed. There is no "One Quick Explanation" if you want full understanding of how odeXY works. I did realize that all the linking and such in the description may be cumbersome though. When I have the time, I might come back and split this video up into individual parts. In the meantime, I can direct you to a shorter, less detailed video by someone else if you're interested.
@jorgemercent2995
@jorgemercent2995 3 жыл бұрын
I am fucking lost at the state blahbablh what ever that is
Matlab ode45 Tutorial Part 2A: Multidimensional Problems
27:33
Scholastic Samaritan
Рет қаралды 11 М.
Matlab ode45 Tutorial Part 2C: A Matrix Method (Faster)
40:42
Scholastic Samaritan
Рет қаралды 10 М.
마시멜로우로 체감되는 요즘 물가
00:20
진영민yeongmin
Рет қаралды 29 МЛН
Clowns abuse children#Short #Officer Rabbit #angel
00:51
兔子警官
Рет қаралды 59 МЛН
Дарю Самокат Скейтеру !
00:42
Vlad Samokatchik
Рет қаралды 7 МЛН
Lec13 Solving ODEs using ode45 in Matlab
40:37
Jose Gutierrez
Рет қаралды 45 М.
Matlab ode45 Tutorial Part 2B: Another 2D Example
28:29
Scholastic Samaritan
Рет қаралды 8 М.
What does it feel like to invent math?
15:08
3Blue1Brown
Рет қаралды 4,1 МЛН
Mastering MATLAB Function Handles: An Introduction and Practical Examples
8:58
The Man Who Solved the World’s Most Famous Math Problem
11:14
Newsthink
Рет қаралды 657 М.
Ordinary Differential Equations and Dynamic Systems in Simulink
44:58
Christopher Lum
Рет қаралды 76 М.
Solving Ordinary Differential Equations Using MATLAB
19:37
Simple Code, High Performance
2:50:14
Molly Rocket
Рет қаралды 237 М.
МУЖЧИНА И ТОПОР
0:22
В ТРЕНДЕ
Рет қаралды 4,3 МЛН
Easier when using this tip
1:00
Anh Đầu Bếp
Рет қаралды 21 МЛН
Почаще проводите время с Родителями 🥺❤️
0:51
Dragon Нургелды 🐉
Рет қаралды 1,1 МЛН