Bird
Raised Fist0
MATLABdata~5 mins

ODE solvers (ode45) in MATLAB - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is ode45 used for in MATLAB?

ode45 is a MATLAB function used to solve ordinary differential equations (ODEs) numerically. It is based on a Runge-Kutta method and is good for solving non-stiff ODEs.

Click to reveal answer
beginner
What type of problems is ode45 best suited for?

ode45 works best for solving non-stiff ordinary differential equations where the solution changes smoothly.

Click to reveal answer
beginner
How do you define the function to be solved by ode45?

You define a function that returns the derivative (rate of change) of your variable(s). It usually looks like dy = f(t,y), where t is time and y is the current value.

Click to reveal answer
beginner
What is the basic syntax to call ode45?

The basic syntax is [t,y] = ode45(@odefun, tspan, y0); where @odefun is your function, tspan is the time interval, and y0 is the initial condition.

Click to reveal answer
beginner
What do the outputs t and y from ode45 represent?

t is a column vector of time points where the solution is evaluated. y is a matrix where each row corresponds to the solution at the time in t.

Click to reveal answer
Which MATLAB function is commonly used for solving non-stiff ODEs?
Aode45
Bode15s
Code23s
Dode113
What does the function passed to ode45 return?
AThe time span
BThe derivative of the state variables
CThe initial conditions
DThe solution vector
In the call [t,y] = ode45(@odefun, [0 10], 5);, what does 5 represent?
AStep size
BFinal time
CInitial value of the variable
DDerivative value
What is the output y from ode45?
ATime points vector
BInitial conditions
CDerivative function handle
DSolution values at each time point
If your ODE problem is stiff, which solver is better than ode45?
Aode15s
Bode23
Code45
Dode23t
Explain how to use ode45 to solve a simple ODE in MATLAB.
Think about the steps from writing the function to getting the solution vectors.
You got /5 concepts.
    Describe the difference between stiff and non-stiff ODEs and which MATLAB solvers are suitable for each.
    Consider how the solution behavior affects solver efficiency.
    You got /4 concepts.

      Practice

      (1/5)
      1. What does the MATLAB function ode45 primarily do?
      easy
      A. It solves ordinary differential equations numerically.
      B. It plots graphs of functions automatically.
      C. It calculates the derivative of a function symbolically.
      D. It integrates functions analytically.

      Solution

      1. Step 1: Understand the purpose of ode45

        The ode45 function in MATLAB is designed to solve ordinary differential equations (ODEs) using a numerical method called Runge-Kutta.
      2. Step 2: Compare options with ode45's function

        Options A, C, and D describe plotting, symbolic differentiation, and analytical integration, which are not what ode45 does.
      3. Final Answer:

        It solves ordinary differential equations numerically. -> Option A
      4. Quick Check:

        ode45 solves ODEs numerically = B [OK]
      Hint: Remember ode45 solves ODEs numerically, not symbolically or graphing [OK]
      Common Mistakes:
      • Confusing ode45 with plotting functions
      • Thinking ode45 does symbolic math
      • Assuming ode45 integrates analytically
      2. Which of the following is the correct syntax to call ode45 for solving dy/dt = -2y with initial value y(0)=1 over time interval [0 5]?
      easy
      A. [t,y] = ode45(@(y,t) -2*y, [0 5], 1);
      B. [t,y] = ode45(@(t,y) -2*y, [0 5], 1);
      C. [t,y] = ode45(@(t,y) 2*y, 0:5, 1);
      D. [t,y] = ode45(@(t,y) -2*y, 0, 5, 1);

      Solution

      1. Step 1: Check function handle and argument order

        The function handle for ode45 must be @(t,y) for time t and variable y. [t,y] = ode45(@(t,y) -2*y, [0 5], 1); uses @(t,y) correctly with the expression -2*y.
      2. Step 2: Verify time span and initial value format

        Time span must be a vector [0 5], and initial value is a scalar 1. [t,y] = ode45(@(t,y) -2*y, [0 5], 1); matches this format exactly.
      3. Final Answer:

        [t,y] = ode45(@(t,y) -2*y, [0 5], 1); -> Option B
      4. Quick Check:

        Correct syntax: @(t,y), time vector, initial value = A [OK]
      Hint: Use @(t,y) for function and time vector in brackets [OK]
      Common Mistakes:
      • Swapping t and y in function handle
      • Using colon operator instead of vector for time span
      • Passing time points as separate arguments
      3. Consider the code:
      f = @(t,y) t - y;
      [t,y] = ode45(f, [0 2], 1);
      disp(y(end));

      What is the output approximately?
      medium
      A. 1.3
      B. 1.0
      C. 0.5
      D. 2.0

      Solution

      1. Step 1: Understand the ODE and initial condition

        The ODE is dy/dt = t - y with y(0) = 1, solved over [0 2]. This is a linear ODE where y tends to follow t but is pulled down by -y.
      2. Step 2: Estimate solution behavior at t=2

        Numerical solution with ode45 typically gives y around 1.3 at t=2 for this ODE and initial value.
      3. Final Answer:

        1.3 -> Option A
      4. Quick Check:

        ode45 output y(end) ≈ 1.3 for dy/dt = t - y [OK]
      Hint: Recall ode45 returns solution array; last value is y at final time [OK]
      Common Mistakes:
      • Assuming output equals initial value
      • Confusing function input order
      • Ignoring numerical approximation
      4. Identify the error in this code snippet:
      f = @(y,t) y^2 - t;
      [t,y] = ode45(f, [0 1], 0);
      plot(t,y);
      medium
      A. Time span must be a column vector.
      B. Initial value cannot be zero.
      C. Function handle arguments are in wrong order.
      D. Plot command is missing labels.

      Solution

      1. Step 1: Check function handle argument order

        ODE functions for ode45 must have arguments in order (t,y), but here it is @(y,t), which is incorrect.
      2. Step 2: Verify other parts of the code

        Initial value zero is allowed, time span as [0 1] is valid, and plot labels are optional, so these are not errors.
      3. Final Answer:

        Function handle arguments are in wrong order. -> Option C
      4. Quick Check:

        Function handle must be @(t,y), not @(y,t) [OK]
      Hint: Always use @(t,y) for ode45 function handles [OK]
      Common Mistakes:
      • Swapping t and y in function handle
      • Thinking initial value can't be zero
      • Believing time span must be column vector
      5. You want to solve the system:
      dx/dt = y
      dy/dt = -x

      with initial conditions x(0)=0, y(0)=1 over [0 10]. Which MATLAB code correctly uses ode45 to solve this system?
      hard
      A. f = @(t,u) [u(1); u(2)]; [t,u] = ode45(f, [0 10], [0 1]);
      B. f = @(t,x,y) [y; -x]; [t,u] = ode45(f, [0 10], [0 1]);
      C. f = @(u,t) [u(2); -u(1)]; [t,u] = ode45(f, [0 10], [0 1]);
      D. f = @(t,u) [u(2); -u(1)]; [t,u] = ode45(f, [0 10], [0 1]);

      Solution

      1. Step 1: Define function handle for system of ODEs

        The system has two variables x and y, combined as vector u where u(1)=x and u(2)=y. The function must be @(t,u) returning [y; -x], which is [u(2); -u(1)].
      2. Step 2: Check initial conditions and call to ode45

        Initial conditions are [0 1] for x=0 and y=1. Time span is [0 10]. f = @(t,u) [u(2); -u(1)]; [t,u] = ode45(f, [0 10], [0 1]); matches this exactly.
      3. Final Answer:

        f = @(t,u) [u(2); -u(1)]; [t,u] = ode45(f, [0 10], [0 1]); -> Option D
      4. Quick Check:

        System ODEs use @(t,u) with vector u = D [OK]
      Hint: Use vector input @(t,u) and return derivatives as vector [OK]
      Common Mistakes:
      • Using separate arguments for variables in function handle
      • Swapping order of arguments in function handle
      • Returning wrong derivative vector
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard