Question
MATLAB Use a for loop and conditionals (if or switch) to creates a Fibonacci matrix, defined as follows. The Fibonacci matrix is constructed by starting
MATLAB
Use a for loop and conditionals (if or switch) to creates a Fibonacci matrix, defined as follows. The Fibonacci matrix is constructed by starting with the matrix [1 1] and repeatedly concatenating a square matrix whose size in each dimension, and values, correspond to the size of the longest edge of the current matrix. Matrices are concatenated in counterclockwise order, starting by concatenating a 2 by 2 matrix of 2s to the top of [1 1]. See below for a Fibonacci matrix with 8 as its largest number:
Use your loop to create a Fibonacci matrix with 4181 as its largest value; that is, the final result should be a 6765 (the next Fibonacci) by 4181 matrix with the number 4181 as its largest value. Store this matrix as fib4181 (3 points).
code to generate fibonacci numbers:
N=8; %Fibonacci number to find
fnMinus1=0; %zero'th Fibonacci number
fn=1; %first Fibonacci number
for i=2:N %remember, we started with the first
fnPlus1=fn+fnMinus1; %find the newest Fibonacci number
fnMinus1=fn; %update second-previous number
fn=fnPlus1; %update first-previous number
end
fn
Use a for loop and conditionals (if or switch) to creates a Fibonacci matrix, defined as follows. The Fibonacci matrix is constructed by starting with the matrix [1 1] and repeatedly concatenating a square matrix whose size in each dimension, and values, correspond to the size of the longest edge of the current matrix. Matrices are concatenated in counterclockwise order, starting by concatenating a 2 by 2 matrix of 2s to the top of [1 1]. See below for a Fibonacci matrix with 8 as its largest number: 3 3 3 2 2 8 8 8 8 8 8 8 8 3 3 3 2 2 8 8 8 8 8 8 8 8 3 3 3 1 1 8 8 8 8 8 8 8 8 5 5 5 5 5 8 8 8 8 8 8 8 8 5 5 5 5 5 8 8 8 8 8 8 8 8 5 5 5 5 5 8 8 8 8 8 8 8 8 5 5 5 5 5 8 8 8 8 8 8 8 8 5 5 5 5 5 8 8 8 8 8 8 8 8 0 0 0 0 The color-coding above is simply a visual aid for demonstrating the structure of the matrix; you don't need to color-code your solution (and I don't know how you would...) Use your loop to create a Fibonacci matrix with 4181 as its largest value; that is, the final result should be a 6765 (the next Fibonacci) by 4181 matrix with the number 4181 as its largest value. Store this matrix as fib4181 (3 points). HINT: A common question is how do I alternate which side I'm concatenating on?" That's what you should use the conditional for. One way to do this is to make a condition that cycles through the same four values and determine the side of concatenation from those values. There are many ways to do this; for example, the mod function can be helpful, or you can create an additional counter variable. HINT: Feel free to adapt the code to generate Fibonacci numbers from W3D1 slide 23. 4181 is the 19th Fibonacci number, but it is not necessary to calculate it directly in order to solve thisStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started