Solve Differential Equations in MATLAB and Simulink

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น •

  • @antonioperez3589
    @antonioperez3589 3 ปีที่แล้ว +5

    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.

    • @apm
      @apm  3 ปีที่แล้ว +1

      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

  • @julianavarro6915
    @julianavarro6915 3 ปีที่แล้ว +1

    How would one solve an ODE that has variable coefficients? For example y''+1/x *y'+y=0. (where y(x))

    • @apm
      @apm  3 ปีที่แล้ว

      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).

  • @saerdnakaliber472
    @saerdnakaliber472 4 ปีที่แล้ว +2

    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?

    • @apm
      @apm  4 ปีที่แล้ว +1

      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
      @deepaksaikumar5178 4 ปีที่แล้ว +2

      @@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...

    • @apm
      @apm  4 ปีที่แล้ว

      @@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

    • @deepaksaikumar5178
      @deepaksaikumar5178 4 ปีที่แล้ว

      @@apm oh! Thank you for your efforts ❤️. Love from India

    • @deepaksaikumar5178
      @deepaksaikumar5178 4 ปีที่แล้ว

      @@apm could you please send me the code for differential equations on matlab. A humble request

  • @satishlukka1454
    @satishlukka1454 3 ปีที่แล้ว +1

    How to give different initial conditions for different variables (like two different values for two differential equations)

    • @apm
      @apm  3 ปีที่แล้ว

      There is additional information on more variables later in the video - keep watching!

    • @satishlukka1454
      @satishlukka1454 3 ปีที่แล้ว +1

      @@apm
      You have given same initial condition for both differential equations which is 0.5

    • @apm
      @apm  3 ปีที่แล้ว

      @@satishlukka1454 you can feed in an array of values that are different.

  • @priyajeni5560
    @priyajeni5560 3 ปีที่แล้ว +2

    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

    • @apm
      @apm  3 ปีที่แล้ว +1

      apmonitor.com/pdc/index.php/Main/SecondOrderSystems This link will help with 2nd order systems. You can either use ode45 or Python ODEINT

    • @priyajeni5560
      @priyajeni5560 3 ปีที่แล้ว +1

      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 ....

    • @charlesrac1ify
      @charlesrac1ify 3 ปีที่แล้ว

      Kindly Help us sir... Thank You so much 🙏

  • @sayanjitb
    @sayanjitb 4 ปีที่แล้ว +1

    why do we use simulink even if we have had matlab? Are there extra advantages?

    • @apm
      @apm  4 ปีที่แล้ว

      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.

    • @sayanjitb
      @sayanjitb 4 ปีที่แล้ว

      @@apm wow, awsome sir. Thank you so much indeed!

  • @cameronspalding9792
    @cameronspalding9792 5 ปีที่แล้ว +2

    If it’s a higher order differential equation: do you set it up as a vector equation

    • @apm
      @apm  5 ปีที่แล้ว

      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.

  • @eefrank-y9l
    @eefrank-y9l 7 ปีที่แล้ว +1

    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!

    • @Hudmyq
      @Hudmyq 6 ปีที่แล้ว

      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.

  • @ajoykumardas4322
    @ajoykumardas4322 3 ปีที่แล้ว +1

    What are the steps of solving differential equations with simulink

    • @apm
      @apm  3 ปีที่แล้ว

      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

    • @ajoykumardas4322
      @ajoykumardas4322 3 ปีที่แล้ว

      Unable to understand please can you write the answer I want for my examination

    • @apm
      @apm  3 ปีที่แล้ว

      @@ajoykumardas4322 sorry, I can't help with exams.

    • @ajoykumardas4322
      @ajoykumardas4322 3 ปีที่แล้ว

      I want the steps of solving the differential equations with Simulink

  • @karthikasankar9215
    @karthikasankar9215 4 ปีที่แล้ว +1

    Thank You Sir. Can you please share matlab program for Kronig penney model ?

    • @apm
      @apm  4 ปีที่แล้ว +2

      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

    • @karthikasankar9215
      @karthikasankar9215 4 ปีที่แล้ว

      @@apm Sir, Can you please share the matlab codes for getting the reflection spectrum of one dimensional photonic crystals ?

  • @ishitva420scifi69
    @ishitva420scifi69 4 ปีที่แล้ว +1

    Can I solve system of 2nd order diff eqn with this??

    • @apm
      @apm  4 ปีที่แล้ว +1

      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)

  • @wenqingqiu2569
    @wenqingqiu2569 4 ปีที่แล้ว +1

    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
      @apm  4 ปีที่แล้ว +1

      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.

    • @wenqingqiu2569
      @wenqingqiu2569 4 ปีที่แล้ว +1

      ​@@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)

    • @apm
      @apm  4 ปีที่แล้ว

      @@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

  • @eefrank-y9l
    @eefrank-y9l 7 ปีที่แล้ว +1

    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)

    • @apm
      @apm  7 ปีที่แล้ว

      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.

    • @eefrank-y9l
      @eefrank-y9l 7 ปีที่แล้ว

      thanks

  • @gianfrancodelgiudice4926
    @gianfrancodelgiudice4926 4 ปีที่แล้ว +1

    How could I solve a second order differential equation with the same block in simulink?

    • @apm
      @apm  4 ปีที่แล้ว +2

      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

    • @gianfrancodelgiudice4926
      @gianfrancodelgiudice4926 4 ปีที่แล้ว

      @@apm Thanks a lot for the fast reply

  • @saxonelyaman9212
    @saxonelyaman9212 5 ปีที่แล้ว +1

    what is the purpose of making time = z.x and y=z.y?

    • @apm
      @apm  5 ปีที่แล้ว

      It is just for convenience to rename them for use later in plots or other analysis.

  • @whitenancy4349
    @whitenancy4349 7 ปีที่แล้ว

    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.

    • @apm
      @apm  7 ปีที่แล้ว

      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)

  • @luzalejo5887
    @luzalejo5887 7 ปีที่แล้ว +1

    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.

    • @apm
      @apm  7 ปีที่แล้ว

      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.

  • @chiragraju821
    @chiragraju821 4 ปีที่แล้ว +1

    Not working, It says error with the equation line of the code

    • @apm
      @apm  4 ปีที่แล้ว

      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

  • @adamkotler5603
    @adamkotler5603 6 ปีที่แล้ว

    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.

    • @apm
      @apm  6 ปีที่แล้ว

      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).

    • @ajaykhande4583
      @ajaykhande4583 6 ปีที่แล้ว

      Hold on

  • @sarbanibhadra8017
    @sarbanibhadra8017 6 ปีที่แล้ว

    What is the initial value of z i.e. x(3)? Is it the same initial condition set at integrator for y?

    • @apm
      @apm  6 ปีที่แล้ว

      By default it is zero for the integrator but you can change it if you'd like to add an initial condition.

  • @ahsannaseer9433
    @ahsannaseer9433 6 ปีที่แล้ว

    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 ?

    • @apm
      @apm  6 ปีที่แล้ว

      "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

  • @tkayfrmda2
    @tkayfrmda2 4 ปีที่แล้ว +1

    Why do you divide by tau

    • @apm
      @apm  4 ปีที่แล้ว

      All of the non-differential terms have to be on the right hand side of the equation.

  • @shirinothman1172
    @shirinothman1172 6 ปีที่แล้ว

    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.

    • @apm
      @apm  6 ปีที่แล้ว

      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.

    • @shirinothman1172
      @shirinothman1172 6 ปีที่แล้ว +1

      Thank you

  • @sukhmandeepkaur9714
    @sukhmandeepkaur9714 4 ปีที่แล้ว +1

    how to solve if i have dx/dz=f(x,T) and dT/dz=g(x,T)

    • @apm
      @apm  4 ปีที่แล้ว

      There is an example with 2 differential equations later in the video.

    • @sukhmandeepkaur9714
      @sukhmandeepkaur9714 4 ปีที่แล้ว +1

      @@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

    • @apm
      @apm  4 ปีที่แล้ว

      @@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

  • @kidusbahiru4369
    @kidusbahiru4369 5 ปีที่แล้ว +2

    can you do a simple differential equation

    • @apm
      @apm  5 ปีที่แล้ว +2

      There are additional tutorials here: apmonitor.com/che263/index.php/Main/MatlabDynamicSim and apmonitor.com/che436/index.php/Main/ProjectProgramming

  • @nimishjoshi1420
    @nimishjoshi1420 7 ปีที่แล้ว

    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

    • @apm
      @apm  7 ปีที่แล้ว

      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.

    • @nimishjoshi1420
      @nimishjoshi1420 7 ปีที่แล้ว

      Thanks sir! can i have your contact if i require more help or something like that,Your help will be appreciated.

    • @nimishjoshi1420
      @nimishjoshi1420 7 ปีที่แล้ว

      or can you ping me at joshinimish12@gmail.com

    • @apm
      @apm  7 ปีที่แล้ว

      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.

    • @nimishjoshi1420
      @nimishjoshi1420 7 ปีที่แล้ว +1

      Thanks alot

  • @saeednasim8704
    @saeednasim8704 6 ปีที่แล้ว

    The last one was done by simulink. But I need the solution with matlab. Please someone help.

    • @apm
      @apm  6 ปีที่แล้ว

      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

  • @madhur4190
    @madhur4190 5 ปีที่แล้ว +3

    this was great. Thanks a lot

  • @ikraikra8845
    @ikraikra8845 6 ปีที่แล้ว

    Sir plz help me in my assignmnt ..i have to prepare any model of diffrential equation

    • @apm
      @apm  6 ปีที่แล้ว +2

      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

    • @ikraikra8845
      @ikraikra8845 6 ปีที่แล้ว

      Its okay sir

  • @yumijung202
    @yumijung202 6 ปีที่แล้ว

    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 ?

    • @apm
      @apm  6 ปีที่แล้ว

      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.

  • @haddedarbia4141
    @haddedarbia4141 7 ปีที่แล้ว

    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

    • @rrc
      @rrc 7 ปีที่แล้ว

      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.

  • @hgfgvvccgvcvvhhvcg145
    @hgfgvvccgvcvvhhvcg145 6 ปีที่แล้ว

    What is ode23 please

    • @apm
      @apm  6 ปีที่แล้ว +1

      ode23 is a differential equation solver: www.mathworks.com/help/matlab/ref/ode23.html

  • @santoshipanigrahi5093
    @santoshipanigrahi5093 5 ปีที่แล้ว

    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

    • @apm
      @apm  5 ปีที่แล้ว

      Sorry, I don't have that one off-hand. Here is additional content that may help you: apmonitor.com/che263/index.php/Main/MatlabDynamicSim

  • @MrMuscleTroll
    @MrMuscleTroll 4 ปีที่แล้ว

    this is not for beginners right? because I don't understand anything at all

    • @apm
      @apm  4 ปีที่แล้ว

      That is correct. A beginner course is available at apmonitor.github.io/begin_matlab

    • @MrMuscleTroll
      @MrMuscleTroll 4 ปีที่แล้ว +1

      @@apm thank you for sharing!

  • @astafzciba
    @astafzciba 6 ปีที่แล้ว

    maybe some numerical discretization examples next time?

    • @apm
      @apm  6 ปีที่แล้ว

      Here is a tutorial on orthogonal collocation on finite elements for solving differential equations: apmonitor.com/do/index.php/Main/OrthogonalCollocation

  • @renzoalvaroshan2625
    @renzoalvaroshan2625 4 ปีที่แล้ว +2

    Matlab conclusion 6:51
    Simulink 9:35

    • @beoptimistic5853
      @beoptimistic5853 3 ปีที่แล้ว

      th-cam.com/video/vFDMaHQ4kW8/w-d-xo.html .💐.

  • @paugasolina5048
    @paugasolina5048 5 ปีที่แล้ว +3

    wasup bro

  • @djamelbenkheira4538
    @djamelbenkheira4538 6 ปีที่แล้ว +1

    thank you sir very very very very very very much

  • @alexharijanto780
    @alexharijanto780 3 ปีที่แล้ว +1

    thank you

    • @beoptimistic5853
      @beoptimistic5853 3 ปีที่แล้ว

      th-cam.com/video/vFDMaHQ4kW8/w-d-xo.html 💐.

  • @michalispotamitis1456
    @michalispotamitis1456 7 ปีที่แล้ว

    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.

    • @apm
      @apm  7 ปีที่แล้ว

      +rew sot, that sounds like a great 2nd order example. Thanks for offering it to others.

    • @usmanismail7536
      @usmanismail7536 7 ปีที่แล้ว

      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

    • @UNICORNCSU
      @UNICORNCSU 6 ปีที่แล้ว

      cool. could you pls share? sucs66 at gmail. thanks a lot.

  • @pacificknight414
    @pacificknight414 4 ปีที่แล้ว +1

    really confusing and lengthy

    • @apm
      @apm  4 ปีที่แล้ว

      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

  • @lightninbolt74
    @lightninbolt74 4 ปีที่แล้ว +6

    Mathematica does this in 3 lines lmao!

    • @apm
      @apm  4 ปีที่แล้ว +3

      Mathematica is also a great tool!

    • @andreimadalin6207
      @andreimadalin6207 3 ปีที่แล้ว +1

      But where is the fun tho

  • @ethiopiatuday1637
    @ethiopiatuday1637 3 ปีที่แล้ว +1

    10Q

    • @beoptimistic5853
      @beoptimistic5853 3 ปีที่แล้ว

      th-cam.com/video/vFDMaHQ4kW8/w-d-xo.html 💐.

  • @shahzadhasan8369
    @shahzadhasan8369 3 ปีที่แล้ว +1

    too complicated

    • @apm
      @apm  3 ปีที่แล้ว

      Module 11 may help apmonitor.com/che263/index.php/Main/DataScience

  • @bigfuss4135
    @bigfuss4135 6 ปีที่แล้ว

    Oh man this trial and error in almost everything is boring.

    • @apm
      @apm  6 ปีที่แล้ว

      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.

    • @bigfuss4135
      @bigfuss4135 6 ปีที่แล้ว

      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!

  • @rhamby3470
    @rhamby3470 3 ปีที่แล้ว

    i hate this shit i dont understand cs majors lmao

  • @fatmaalawadhi5789
    @fatmaalawadhi5789 4 ปีที่แล้ว +1

    How can I find the differential equation from the transfer function using MATLAB and Simulink?

    • @apm
      @apm  4 ปีที่แล้ว

      How about ilaplace function? www.mathworks.com/help/symbolic/ilaplace.html