Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction Session 4. Generate the first N Fibonacci #s 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,... The nth Fibonacci number is the sum of the.

Similar presentations


Presentation on theme: "Introduction Session 4. Generate the first N Fibonacci #s 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,... The nth Fibonacci number is the sum of the."— Presentation transcript:

1 Introduction Session 4

2 Generate the first N Fibonacci #s 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,... The nth Fibonacci number is the sum of the previous two numbers. In other words, F n =F n-1 +F n-2 F 0 =0, F 1 =1

3 Generate the first N Fibonacci #s Human language: Generating a list of the first n Fibonacci numbers involves knowing what the value of “n” is. Creating an empty vector called myFibs with n spots Fill spot 1 with 0 and spot 2 with 1 For each spot number, starting with 3, and ending with n, fill that spot with the sum of what’s in the previous two spots Output the list of numbers Programming Language: fibonacci = function(n){ myFibs = rep(0,n) myFibs[1] = 0 myFibs[2] = 1 for(spot in 3:n){ myFibs[spot] = myFibs[spot-1] + myFibs[spot-2] } return(myFibs) }

4 Polar Coordinates

5 Matrix Multiplication


Download ppt "Introduction Session 4. Generate the first N Fibonacci #s 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,... The nth Fibonacci number is the sum of the."

Similar presentations


Ads by Google