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).
- 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 vectorb
where the first two coordinates are \(1\) and the rest are \(0\text{.}\) The commandseye
,diag
,ones
, andzeros
will help. - 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:
- Create a 10×10 matrix A with 2 on the main diagonal, and -1 next to it (both above and below).
- 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{.}\) - 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.