First of all, thanks for the tutorial. I would like to know if other input functions could be applied, different from the step function, e.g., a sinusoidal function. When I try to do it, I find some errors related to the size of the output of @(t,y)first_order(t,y,u): "Error using odearguments (line 93) @(T,Y)FIRST_ORDER(T,Y,U) must reutrn a column vector. Error in ode23 (line 114)...." When I defined, I took into account the ./ division to avoid matrix multiplication. Thanks in advance.
Here is additional help with MATLAB ode23: www.mathworks.com/help/matlab/ref/ode23.html and APM Matlab as an alternative: apmonitor.com/che263/index.php/Main/MatlabDynamicSim
Here is help on 2nd order differential equations. apmonitor.com/wiki/index.php/Apps/2ndOrderDifferential The x is the dependent variable instead of time (t).
Hey guys I have an exam on friday, can you please help me with these questions? I do not understand why ODE45 would not be good for a stiff problem. I mean, should it not be more suitable to use an adaptive method like ODE45 in order to get the most accurate solution for a stiff system, since it adapts its step-size according to the real solution? I know that it takes more time to obtain the solution, but it should be more accurate than ODE15s which does not have this adaptive ability and therefore increases the approximation of the solution? Am I the one understanding everything in reverse? Is the solver-choice based on the time consumption rather than accuracy?
Here is additional information on ODE solvers www.mathworks.com/help/matlab/math/choose-an-ode-solver.html that will answer your questions. Best wishes on your exam!
@@deepaksaikumar5178 I don't have tutorials on that particular topic but here are some resources that may help: apmonitor.com/che263/index.php/Main/MatlabDynamicSim
Sir if i have two functions in same equation like f and g ...how to use ode45 to plot graph...pls help me... My equation is f'''-2(f'+g')f'+(f+g)f''-Mf'=0 BC f(0)=0 f'(0)=1 g(0)=0 g'(0)=0.3 M=0.5
Thank you ...Really the link most helpful to me...sir i have some doubts in my MATLAB code...if possible could you please guide me the corrections ....
The advantage of simulink is that you can break down a complex system into blocks that show the flow of information with lines. I prefer Matlab scripts but it is an alternative that has a nice graphical interface to the models.
Yes, you can solve more than one ODE simultaneously. You return a vector of derivatives and your initial conditions are the same size as the derivatives that are returned from your model function.
Sir, in your example, y=ode23('first_order',t,y0) calculates y. Then how to find out dy? should I apply dy=first_order(t,y) after I got y by ode23? thanks!
This video shows how to solve ODEs with Simulink. Here is additional help as well: apmonitor.com/che436/index.php/Main/ProjectProgramming If you'd like to try Python, here is another tutorial: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
Does this help? github.com/topics/kronig-penney-model You may need to install Python. Here is a brief tutorial on differential equations in Python: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
Yes, just keep watching at 15:55 There is more information on 2nd order systems at apmonitor.com/che436/index.php/Main/LectureNotes20 and apmonitor.com/pdc/index.php/Main/SecondOrderSystems (Python)
Hallo, is there any way that i can simplify "u = x(1); y = x(2); z = x(3);"? Cause i have multi equations. For example, i can smplify "dxdt(1) = dydt; dxdt(2) = dzdt;" as"dxdt = [dydt; dzdt]". Thank you so much in advance for your help:)
@@apm Hello sir, i have another question, it's really nice if you could help me. I want to still use ode_function within a MATLAB function block in Simulink, and cause ode not supported for code generation, so i'm trying to call a function (in a m file) with ode in the MATLAB function block. But i want to pass a value from Simulink to that m file, i have already tried assignin and save (in mat), both also not supported for code generation. Have you any other idea? (this link maybe help what am i trying to say: stackoverflow.com/questions/60283914/solving-odes-in-simulink-without-using-interpreted-matlab-function)
@@wenqingqiu2569 You could try to linearize your differential equations and include a state space block. Here are a few additional ideas: apmonitor.com/che436/index.php/Main/CaseStudyCSTR
Thank you so much sir. I have a question that I would like to ask you If I have an equation: dy/dx = 8*y^k - 3*y The given numbers: k=[0.1:0.01:0.2] y0=0.6 x=[0 10] y1=2 How can I use ODE to solve the equation and use that solution to find x1 (x1 is at y1) for every value of k. CANNOT use arrayfun or find.
The "x" can be substituted for "time" as the dependent variable. Unfortunately, the ode solvers can only handle initial value problems (you can't enforce the constraint y1=2). I'd recommend dynamic optimization for your problem. Here an example that is related to yours: th-cam.com/video/yuj217itTa8/w-d-xo.html (also see Jennings problem at apmonitor.com/do/index.php/Main/MoreDynamicOptimizationBenchmarks)
Hello! how can I change the initial conditions in the integrator if I have different initial conditions of the system of equations, for example: dxdt=f(x,y) and dydt=f(x,y) when x0=1 and y0=2 at t=t0.
You may have a syntax error. I recommend that you copy the example code exactly. Here are additional examples is you'd like to try Python instead: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
How would one separate both solutions into their own graphs? As opposed to displaying both in one graph. I am having difficulty figuring this out myself. Thank you for the video.
"x" is a state vector at 10:05. It is composed of two values (y and z). Because it is an input to the function, it doesn't matter what you name the variable. It is a placeholder for the integrator to try different values of y and z. The function returns the derivatives at the time, y, and z values. There is additional information on using MATLAB to solve differential equations here: apmonitor.com/che263/index.php/Main/MatlabDynamicSim
HELLO ADMIN. Can you help me with this problem? I need the solution and plot on Matlab for the system with five-second order ordinary differential equations for five variables. In the equations I have x, x',x'',y,y',y",z,z',z",w,w',Q and Q' with variable input u(t) and zero initial conditions.
There are a few examples posted here apmonitor.com/che263/index.php/Main/MatlabDynamicSim that show how to solve complex sets of differential equations. I'd recommend that you start with example code and modify it for your application.
@@apm can you please share your mail id or something, I'll send my code file. actually my equations are not of one order and i cannot write it down here. thanks
@@sukhmandeepkaur9714 unfortunately I can't help with the specifics of the many requests I receive each week. I recommend that you post to a forum such as Mathworks to get support. I can support Python Gekko applications if you'd like to try apmonitor.com/pdc/index.php/Main/PythonDifferentialEquations and post questions to Stack Overflow: stackoverflow.com/questions/tagged/gekko If you want to stay with MATLAB, you can run Python in Matlab: apmonitor.com/che263/index.php/Main/MatlabCallsPython
Check out 16:10 for how to add an additional differential equation. It looks like you are solving equations of motion. MATLAB can solve multiple ODEs but can't solve coupled algebraic equations. You may need to use a MATLAB tool such as APMonitor for Differential and Algebraic Equations (apmonitor.com/do/index.php/Main/DynamicModeling). See the skydiving tutorial for a demonstration of Python, MATLAB, and APMonitor.
Feel free to keep posting on these TH-cam videos. I don't typically have time to delve into the details of individual applications. If you are using APMonitor Optimization Suite for MATLAB, there is a Google e-mail group where you can post questions.
There are additional examples here: apmonitor.com/che263/index.php/Main/MatlabDynamicSim you may also be interested in using Python: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
Unfortunately I can't help with specific assignments. However there's a lot of material on my course websites at apmonitor.com/che263 and apmonitor.com/che436
hadded arbia, that looks like a partial differential equation. you'll need to discretize in space or time yourself before you can use the ODE integrator to solve in the other dimension. you may also want to look at PDE integrators as well.
Here is a tutorial on orthogonal collocation on finite elements for solving differential equations: apmonitor.com/do/index.php/Main/OrthogonalCollocation
I have created the same example but with 2 different matlab_interepreted connected in row/2 functions for better understanding. (calc of dydt first and then use the y output as input to calc of dzdt ) if someone wants it, ask me.
I want it Rew.. Thanks in anticipation I also have some PDEs I want to solve. Please help me out, I don't know how to use MATLAB very well.. U can contact me by mail @: ceusman2016@gmail.com
Thanks for the feedback. Simulink does add extra complication. Maybe try python gekko if you are looking for something simpler: apmonitor.com/pdc/index.php/Main/PythonDifferentialEquations
This video is less scripted than some of my others. Sometimes it helps to see troubleshooting strategy but other times you just want to see the correct methods.
I didn't mean it has something wrong, it is useful in fact but seems longer than it should. Anyways thanks for the effort and I'll watch your other lessons. Merry Christmas and happy new year!
First of all, thanks for the tutorial.
I would like to know if other input functions could be applied, different from the step function, e.g., a sinusoidal function. When I try to do it, I find some errors related to the size of the output of @(t,y)first_order(t,y,u):
"Error using odearguments (line 93)
@(T,Y)FIRST_ORDER(T,Y,U) must reutrn a column vector.
Error in ode23 (line 114)...."
When I defined, I took into account the ./ division to avoid matrix multiplication.
Thanks in advance.
Here is additional help with MATLAB ode23: www.mathworks.com/help/matlab/ref/ode23.html and APM Matlab as an alternative: apmonitor.com/che263/index.php/Main/MatlabDynamicSim
How would one solve an ODE that has variable coefficients? For example y''+1/x *y'+y=0. (where y(x))
Here is help on 2nd order differential equations. apmonitor.com/wiki/index.php/Apps/2ndOrderDifferential The x is the dependent variable instead of time (t).
Hey guys I have an exam on friday, can you please help me with these questions? I do not understand why ODE45 would not be good for a stiff problem. I mean, should it not be more suitable to use an adaptive method like ODE45 in order to get the most accurate solution for a stiff system, since it adapts its step-size according to the real solution? I know that it takes more time to obtain the solution, but it should be more accurate than ODE15s which does not have this adaptive ability and therefore increases the approximation of the solution? Am I the one understanding everything in reverse? Is the solver-choice based on the time consumption rather than accuracy?
Here is additional information on ODE solvers www.mathworks.com/help/matlab/math/choose-an-ode-solver.html that will answer your questions. Best wishes on your exam!
@@apm sir, I have been trying to code for maxwell's equation in phasor form. but I couldn't get the code . could you help me out, please...
@@deepaksaikumar5178 I don't have tutorials on that particular topic but here are some resources that may help: apmonitor.com/che263/index.php/Main/MatlabDynamicSim
@@apm oh! Thank you for your efforts ❤️. Love from India
@@apm could you please send me the code for differential equations on matlab. A humble request
How to give different initial conditions for different variables (like two different values for two differential equations)
There is additional information on more variables later in the video - keep watching!
@@apm
You have given same initial condition for both differential equations which is 0.5
@@satishlukka1454 you can feed in an array of values that are different.
Sir if i have two functions in same equation like f and g ...how to use ode45 to plot graph...pls help me...
My equation is
f'''-2(f'+g')f'+(f+g)f''-Mf'=0
BC f(0)=0 f'(0)=1 g(0)=0 g'(0)=0.3
M=0.5
apmonitor.com/pdc/index.php/Main/SecondOrderSystems This link will help with 2nd order systems. You can either use ode45 or Python ODEINT
Thank you ...Really the link most helpful to me...sir i have some doubts in my MATLAB code...if possible could you please guide me the corrections ....
Kindly Help us sir... Thank You so much 🙏
why do we use simulink even if we have had matlab? Are there extra advantages?
The advantage of simulink is that you can break down a complex system into blocks that show the flow of information with lines. I prefer Matlab scripts but it is an alternative that has a nice graphical interface to the models.
@@apm wow, awsome sir. Thank you so much indeed!
If it’s a higher order differential equation: do you set it up as a vector equation
Yes, you can solve more than one ODE simultaneously. You return a vector of derivatives and your initial conditions are the same size as the derivatives that are returned from your model function.
Sir, in your example, y=ode23('first_order',t,y0) calculates y.
Then how to find out dy? should I apply dy=first_order(t,y) after I got y by ode23?
thanks!
Just inpsect the function, dy/dt= (-y+ku)/tau. The output of solving this differential equation is the changing value of y corresponding to the time.
What are the steps of solving differential equations with simulink
This video shows how to solve ODEs with Simulink. Here is additional help as well: apmonitor.com/che436/index.php/Main/ProjectProgramming If you'd like to try Python, here is another tutorial: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
Unable to understand please can you write the answer I want for my examination
@@ajoykumardas4322 sorry, I can't help with exams.
I want the steps of solving the differential equations with Simulink
Thank You Sir. Can you please share matlab program for Kronig penney model ?
Does this help? github.com/topics/kronig-penney-model You may need to install Python. Here is a brief tutorial on differential equations in Python: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
@@apm Sir, Can you please share the matlab codes for getting the reflection spectrum of one dimensional photonic crystals ?
Can I solve system of 2nd order diff eqn with this??
Yes, just keep watching at 15:55 There is more information on 2nd order systems at apmonitor.com/che436/index.php/Main/LectureNotes20 and apmonitor.com/pdc/index.php/Main/SecondOrderSystems (Python)
Hallo, is there any way that i can simplify "u = x(1); y = x(2); z = x(3);"? Cause i have multi equations.
For example, i can smplify "dxdt(1) = dydt; dxdt(2) = dzdt;" as"dxdt = [dydt; dzdt]".
Thank you so much in advance for your help:)
You could use x(1), x(2), x(3) in your equations. In Python you can write u,y,z = x but MATLAB doesn't have a convenient equivalent.
@@apm Hello sir, i have another question, it's really nice if you could help me.
I want to still use ode_function within a MATLAB function block in Simulink, and cause ode not supported for code generation, so i'm trying to call a function (in a m file) with ode in the MATLAB function block.
But i want to pass a value from Simulink to that m file, i have already tried assignin and save (in mat), both also not supported for code generation. Have you any other idea?
(this link maybe help what am i trying to say: stackoverflow.com/questions/60283914/solving-odes-in-simulink-without-using-interpreted-matlab-function)
@@wenqingqiu2569 You could try to linearize your differential equations and include a state space block. Here are a few additional ideas: apmonitor.com/che436/index.php/Main/CaseStudyCSTR
The 2nd one is, after I apply ode23, how I know the value of the state variable at a specific timing point, like @ tx (tx=0.01234)
You can tell ode23 what times you'd like to report the solution. You feed in a time vector with all the time points that you request.
thanks
How could I solve a second order differential equation with the same block in simulink?
There is a 2nd order example later in the video. Also, here is more info on 2nd order systems: apmonitor.com/pdc/index.php/Main/SecondOrderSystems
@@apm Thanks a lot for the fast reply
what is the purpose of making time = z.x and y=z.y?
It is just for convenience to rename them for use later in plots or other analysis.
Thank you so much sir.
I have a question that I would like to ask you
If I have an equation: dy/dx = 8*y^k - 3*y The given numbers: k=[0.1:0.01:0.2] y0=0.6 x=[0 10] y1=2 How can I use ODE to solve the equation and use that solution to find x1 (x1 is at y1) for every value of k. CANNOT use arrayfun or find.
The "x" can be substituted for "time" as the dependent variable. Unfortunately, the ode solvers can only handle initial value problems (you can't enforce the constraint y1=2). I'd recommend dynamic optimization for your problem. Here an example that is related to yours: th-cam.com/video/yuj217itTa8/w-d-xo.html (also see Jennings problem at apmonitor.com/do/index.php/Main/MoreDynamicOptimizationBenchmarks)
Hello! how can I change the initial conditions in the integrator if I have different initial conditions of the system of equations, for example: dxdt=f(x,y) and dydt=f(x,y) when x0=1 and y0=2 at t=t0.
Luz Alejo Alvarez, double click the integrator and set the initial condition to [x0,y0]. You can also do this at 4:15 if you aren't using Simulink.
Not working, It says error with the equation line of the code
You may have a syntax error. I recommend that you copy the example code exactly. Here are additional examples is you'd like to try Python instead: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
How would one separate both solutions into their own graphs? As opposed to displaying both in one graph. I am having difficulty figuring this out myself.
Thank you for the video.
You can either do figure(1) and then figure(2) or else you can make two subplots with subplot(2,1,1) and subplot(2,1,2).
Hold on
What is the initial value of z i.e. x(3)? Is it the same initial condition set at integrator for y?
By default it is zero for the integrator but you can change it if you'd like to add an initial condition.
Sir, what is 'x' here? You haven't defined it ? and also why you have to multily "z.x" and "z.y" in order to get time and derivative value ?
"x" is a state vector at 10:05. It is composed of two values (y and z). Because it is an input to the function, it doesn't matter what you name the variable. It is a placeholder for the integrator to try different values of y and z. The function returns the derivatives at the time, y, and z values. There is additional information on using MATLAB to solve differential equations here: apmonitor.com/che263/index.php/Main/MatlabDynamicSim
Why do you divide by tau
All of the non-differential terms have to be on the right hand side of the equation.
HELLO ADMIN. Can you help me with this problem? I need the solution and plot on Matlab for the system with five-second order ordinary differential equations for five variables. In the equations I have x, x',x'',y,y',y",z,z',z",w,w',Q and Q' with variable input u(t) and zero initial conditions.
There are a few examples posted here apmonitor.com/che263/index.php/Main/MatlabDynamicSim that show how to solve complex sets of differential equations. I'd recommend that you start with example code and modify it for your application.
Thank you
how to solve if i have dx/dz=f(x,T) and dT/dz=g(x,T)
There is an example with 2 differential equations later in the video.
@@apm can you please share your mail id or something, I'll send my code file. actually my equations are not of one order and i cannot write it down here.
thanks
@@sukhmandeepkaur9714 unfortunately I can't help with the specifics of the many requests I receive each week. I recommend that you post to a forum such as Mathworks to get support. I can support Python Gekko applications if you'd like to try apmonitor.com/pdc/index.php/Main/PythonDifferentialEquations and post questions to Stack Overflow: stackoverflow.com/questions/tagged/gekko If you want to stay with MATLAB, you can run Python in Matlab: apmonitor.com/che263/index.php/Main/MatlabCallsPython
can you do a simple differential equation
There are additional tutorials here: apmonitor.com/che263/index.php/Main/MatlabDynamicSim and apmonitor.com/che436/index.php/Main/ProjectProgramming
what if we have 2 variables..I need a differential equation of s=ut+1/2at^2; And also tell me how can we write v=u+at as well thank You
Check out 16:10 for how to add an additional differential equation. It looks like you are solving equations of motion. MATLAB can solve multiple ODEs but can't solve coupled algebraic equations. You may need to use a MATLAB tool such as APMonitor for Differential and Algebraic Equations (apmonitor.com/do/index.php/Main/DynamicModeling). See the skydiving tutorial for a demonstration of Python, MATLAB, and APMonitor.
Thanks sir! can i have your contact if i require more help or something like that,Your help will be appreciated.
or can you ping me at joshinimish12@gmail.com
Feel free to keep posting on these TH-cam videos. I don't typically have time to delve into the details of individual applications. If you are using APMonitor Optimization Suite for MATLAB, there is a Google e-mail group where you can post questions.
Thanks alot
The last one was done by simulink. But I need the solution with matlab. Please someone help.
There are additional examples here: apmonitor.com/che263/index.php/Main/MatlabDynamicSim you may also be interested in using Python: apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations
this was great. Thanks a lot
Sir plz help me in my assignmnt ..i have to prepare any model of diffrential equation
Unfortunately I can't help with specific assignments. However there's a lot of material on my course websites at apmonitor.com/che263 and apmonitor.com/che436
Its okay sir
if I want to know y in any form of x: example dy/dt =yt ,y=e^((t^2)/(2)) , i want to know y in function x
Can I write code in any form ?
For the ODE solvers, you have to write the equation in semi-explicit form as dx/dt = f(x). It solves the equation numerically, not analytically.
hi plz can u help me to solve this equation using matlab : dy/dx=(1/x)*y-db/dt here b is a vector of 10000 rows any suggestion plz
hadded arbia, that looks like a partial differential equation. you'll need to discretize in space or time yourself before you can use the ODE integrator to solve in the other dimension. you may also want to look at PDE integrators as well.
What is ode23 please
ode23 is a differential equation solver: www.mathworks.com/help/matlab/ref/ode23.html
Sir can you send me a Matlab code to plot a delay differential equation x^{\prime}(t)+(t^2+2)x(\sqrt{t^2-1.27})-(1/t^2)x(\sqrt{t^2-2.54})=0
Sorry, I don't have that one off-hand. Here is additional content that may help you: apmonitor.com/che263/index.php/Main/MatlabDynamicSim
this is not for beginners right? because I don't understand anything at all
That is correct. A beginner course is available at apmonitor.github.io/begin_matlab
@@apm thank you for sharing!
maybe some numerical discretization examples next time?
Here is a tutorial on orthogonal collocation on finite elements for solving differential equations: apmonitor.com/do/index.php/Main/OrthogonalCollocation
Matlab conclusion 6:51
Simulink 9:35
th-cam.com/video/vFDMaHQ4kW8/w-d-xo.html .💐.
wasup bro
thank you sir very very very very very very much
thank you
th-cam.com/video/vFDMaHQ4kW8/w-d-xo.html 💐.
I have created the same example but with 2 different matlab_interepreted connected in row/2 functions for better understanding.
(calc of dydt first and then use the y output as input to calc of dzdt )
if someone wants it, ask me.
+rew sot, that sounds like a great 2nd order example. Thanks for offering it to others.
I want it Rew.. Thanks in anticipation
I also have some PDEs I want to solve. Please help me out, I don't know how to use MATLAB very well..
U can contact me by mail @: ceusman2016@gmail.com
cool. could you pls share? sucs66 at gmail. thanks a lot.
really confusing and lengthy
Thanks for the feedback. Simulink does add extra complication. Maybe try python gekko if you are looking for something simpler: apmonitor.com/pdc/index.php/Main/PythonDifferentialEquations
Mathematica does this in 3 lines lmao!
Mathematica is also a great tool!
But where is the fun tho
10Q
th-cam.com/video/vFDMaHQ4kW8/w-d-xo.html 💐.
too complicated
Module 11 may help apmonitor.com/che263/index.php/Main/DataScience
Oh man this trial and error in almost everything is boring.
This video is less scripted than some of my others. Sometimes it helps to see troubleshooting strategy but other times you just want to see the correct methods.
I didn't mean it has something wrong, it is useful in fact but seems longer than it should. Anyways thanks for the effort and I'll watch your other lessons. Merry Christmas and happy new year!
i hate this shit i dont understand cs majors lmao
How can I find the differential equation from the transfer function using MATLAB and Simulink?
How about ilaplace function? www.mathworks.com/help/symbolic/ilaplace.html