Skip to main content

Exercises 2.7 Homework

1.

The Fibonacci numbers \(F_n\) are defined by the following relations: \(F_1=1\text{,}\) \(F_2=1\text{,}\) then \(F_3 = F_1+F_2\text{,}\) \(F_4 = F_2 + F_3\text{,}\) and so on: every number is the sum of two previous ones, \(F_n = F_{n-2}+F_{n-1}\text{.}\) We can consider these relations as a system of linear equations with unknowns \(F_1, \dots, F_n\) (to see this, move all the unknowns to the left, leaving constant terms on the right).

  1. Find the first 30 Fibonacci numbers using Matlab's linear solver A\b. To achieve this, you will first need to create a \(30\times 30\) matrix of the linear system and then create a column vector b where the first two coordinates are \(1\) and the rest are \(0\text{.}\) The commands eye, diag, ones, and zeros will help.
  2. Using the same method, find the first 30 “generalized Fibonacci numbers” that begin with numbers \(p, q\) instead of \(1, 1\text{.}\) Use the first two digits of your SUID number as the starting values \(p, q\text{.}\) (For example, if your SUID begins with 2067… then \(p=2\text{,}\) \(q=0\text{.}\))
2.

Write a script to do the following:

  1. Create a 10×10 matrix A with 2 on the main diagonal, and -1 next to it (both above and below).
  2. Solve the linear system \(Ay=b\) where \(b\) is the vector
    \begin{equation*} \begin{pmatrix} \sqrt{1} \\ \sqrt{2} \\ \vdots \\ \sqrt{10} \end{pmatrix} \end{equation*}
    Use a regularly-spaced vector, transpose, and sqrt to create \(b\text{.}\)
  3. Plot the solution \(y\) against the vector \(x\) of 10 equally spaced numbers, beginning with 0 and ending with 1. The linspace command will be useful.