Exercises 2.7 Homework
1.
The Fibonacci numbers Fn are defined by the following relations: F1=1, F2=1, then F3=F1+F2, F4=F2+F3, and so on: every number is the sum of two previous ones, Fn=Fn−2+Fn−1. We can consider these relations as a system of linear equations with unknowns F1,…,Fn (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×30 matrix of the linear system and then create a column vectorb
where the first two coordinates are 1 and the rest are 0. 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. Use the first two digits of your SUID number as the starting values p,q. (For example, if your SUID begins with 2067… then p=2, q=0.)
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(√1√2⋮√10)Use a regularly-spaced vector, transpose, and
sqrt
to create b. - 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.