Skip to main content
Engineering LibreTexts

4.14: Exercises

  • Page ID
  • \( \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 exercises.

    Exercise 4.1

    Write a loop that computes the first \(n\) elements of the geometric sequence \(A_{i+1} = A_i/2\) with \(A_1 = 1\). Notice that math notation puts \(A_{i+1}\) on the left side of the equality. When you translate to MATLAB, you might want to rewrite it with \(A_{i}\) on the left side.

    Exercise 4.2

    Write an expression that computes the square root of the sum of the squares of the elements of a vector, without using a loop.

    Exercise 4.3

    The ratio of consecutive Fibonacci numbers, \(F_{n+1}/F_{n}\), converges to a constant value as \(n\) increases. Write a script that computes a vector with the first \(n\) elements of a Fibonacci sequence (assuming that the variable n is defined) and then computes a new vector that contains the ratios of consecutive Fibonacci numbers. Plot this vector to see if it seems to converge. What value does it converge on?

    Exercise 4.4

    The following set of equations is based on a famous example of a chaotic system, the Lorenz attractor (see \[\begin{aligned} x_{i+1} &=& x_i + \sigma \left( y_i - x_i \right) dt \\ y_{i+1} &=& y_i + \left[ x_i (r - z_i) - y_i \right] dt \\ z_{i+1} &=& z_i + \left( x_i y_i - b z_i \right) dt\end{aligned}\]

    1. Write a script that computes the first 10 elements of the sequences \(X\), \(Y\), and \(Z\) and stores them in vectors named X, Y, and Z.

      Use the initial values \(X_1 = 1\), \(Y_1 = 2\), and \(Z_1 = 3\) with the values \(\sigma = 10\), \(b = 8/3\), \(r = 28\), and \(dt = 0.01\).

    2. Read the documentation for plot3 and comet3, and plot the results in three dimensions.
    3. Once the code is working, use semicolons to suppress the output and then run the program with sequence lengths of 100, 1,000, and 10,000.
    4. Run the program again with different starting conditions. What effect does it have on the result?
    5. Run the program with different values for \(\sigma\), \(b\), and \(r\), and see if you can get a sense of how each variable affects the system.
    Exercise 4.5

    The logistic map (see is described by the following equation:

    \[X_{i+1} = r X_i (1-X_i) \notag \]

    where \(X_i\) is a number between 0 and 1, and \(r\) is a positive number.

    1. Write a script named logmap.m that computes the first 50 elements of \(X\) with r = 3.9 and X1 = 0.5, where r is the parameter of the logistic map and X1 is the initial value.
    2. Plot the results for a range of values of \(r\) from 2.4 to 4.0. How does the behavior of the system change as you vary \(r\)?

    This page titled 4.14: Exercises is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Carey Smith via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.