Skip to main content
Engineering LibreTexts

10.4: Exercises

  • Page ID
    84739
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Before you go on, you might want to work on the following exercise.

    Exercise 10.2

    Based on the examples we’ve seen so far, you’d think that all ODEs describe population as a function of time, but that’s not true.

    For example, the Lorenz system is a system of differential equations based on a model of fluid dynamics in the atmosphere (see https://greenteapress.com/matlab/lorenz). It turns out to be interesting in part because its solutions are chaotic; that is, small changes in the initial conditions yield big differences in the solutions.

    The system is described by these differential equations: \[\begin{aligned} x_t &=& \sigma (y - x) \\ y_t &=& x (r - z) - y \\ z_t &=& xy - b z\end{aligned}\] Common values for the parameters are \(\sigma = 10\), \(b = 8/3\), and \(r=28\).

    Use ode45 to estimate a solution to this system of equations.

    1. Create a file named lorenz.m with a top-level function named lorenz and a helper function named rate_func.
    2. The rate function should take t and V as input variables, where the components of V are understood to be the current values of x, y, and z. It should compute the corresponding derivatives and return them in a single column vector.
    3. Test the function by calling it from the top-level function with values like \(t=0\), \(x=1\), \(y=2\), and \(z=3\). Once you get your function working, you should make it a silent function before calling ode45.
    4. Use ode45 to estimate the solution for the time span \([0, 30]\) with the initial condition \(x=1\), \(y=2\), and \(z=3\).
    5. Plot the results as a time series, that is, each of the variables as a function of time.
    6. Use plot3 to plot the trajectory of \(x\), \(y\), and \(z\).

    This page titled 10.4: Exercises is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Allen B. Downey (Green Tea Press) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?