Docsity

Math 152 Lab 1: Generating Fibonacci Sequences and Creating a 4x4 Matrix - Prof. Daniel J., Lab Reports of Mathematics

Toggle sidebar
bg1
Math 152 (Spring 2009, Bates) Lab 1
Due February 26, 2009
Be sure to read the instructions in the syllabus about doing/turning in labs!!! A little work up front will
save you lots of work and missed points later!
1. (4 points) The Fibonacci numbers come up often in nature (Wiki them if you don’t believe me). They
are defined as follows:
f1= 1,
f2= 1,and
fi=fi−1+fi−2for i > 2,
i.e., they go 1, 1, 1+1=2, 1+2=3, 2+3=5, 3+5=8,.... Write a for loop that gives as output the
first 20 Fibonacci numbers after the two 1’s at the beginning. Hint: You might need to initialize
some variable(s) before your loop and then change it/them at each step of the loop. Also, note that
print(x); will print out the value of x, even if the output is being supressed (by either a colon or
being contained in a loop ending with a colon).
2. Cook up three more loops based on the previous one to print out the following related sequences:
(a) (1 point) twice each of the first 10 Fibonacci numbers (forgetting about the initial 1’s),
(b) (1 point) the squares of the first 10 Fibonacci numbers (forgetting about the initial 1’s), and
(c) (2 points) 2, 5, 13, 34, 89 (building from the loop in #1).
3. Now for one about matrices:
(a) (1 point) Cook up a pair of for loops (one nested in the other) that populates a 4x4 matrix A
with the (i,j) entry equal to ji.
(b) (1 point) Find the inverse of A, whatever that means.
1

Partial preview of the text

Download Math 152 Lab 1: Generating Fibonacci Sequences and Creating a 4x4 Matrix - Prof. Daniel J. and more Lab Reports Mathematics in PDF only on Docsity!

Math 152 (Spring 2009, Bates) Lab 1

Due February 26, 2009

Be sure to read the instructions in the syllabus about doing/turning in labs!!! A little work up front will save you lots of work and missed points later!

  1. (4 points) The Fibonacci numbers come up often in nature (Wiki them if you don’t believe me). They are defined as follows: f 1 = 1, f 2 = 1, and fi = fi− 1 + fi− 2 for i > 2 , i.e., they go 1, 1, 1+1=2, 1+2=3, 2+3=5, 3+5=8,.... Write a for loop that gives as output the first 20 Fibonacci numbers after the two 1’s at the beginning. Hint: You might need to initialize some variable(s) before your loop and then change it/them at each step of the loop. Also, note that print(x); will print out the value of x, even if the output is being supressed (by either a colon or being contained in a loop ending with a colon).
  2. Cook up three more loops based on the previous one to print out the following related sequences: (a) (1 point) twice each of the first 10 Fibonacci numbers (forgetting about the initial 1’s), (b) (1 point) the squares of the first 10 Fibonacci numbers (forgetting about the initial 1’s), and (c) (2 points) 2, 5, 13, 34, 89 (building from the loop in #1).
  3. Now for one about matrices: (a) (1 point) Cook up a pair of for loops (one nested in the other) that populates a 4x4 matrix A with the (i,j) entry equal to ji. (b) (1 point) Find the inverse of A, whatever that means.