Problem 3095. Return fibonacci sequence do not use loop and condition version 2
Calculate the nth Fibonacci number,return sequence
Given n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...
Examples:
Input n = 2 : 5 Output f is [1 2 3 5] Input n = 7 : 10 Output f is [13 21 34 55]
but, loop and conditional statement is forbidden
Solution Stats
Problem Comments
-
10 Comments
I totally agree with Rafael
I have found a solution. Using
matrix multiplication of [1 1;1 0] and
arrayfun (@ (z) (t ^ z), x-1, 'UniformOutput', 0)
But because 'UniformOutput' contains' for ', it was actually banned, I'm dizzy
@Xinyi Xu You can shorten "UniformOutput" to "Uni"; that should avoid accidentally tripping that particular restriction.
Solution Comments
Show commentsProblem Recent Solvers56
Suggested Problems
-
Make the vector [1 2 3 4 5 6 7 8 9 10]
51235 Solvers
-
Find the longest sequence of 1's in a binary sequence.
6466 Solvers
-
5794 Solvers
-
Back to basics 19 - character types
266 Solvers
-
Create an n-by-n null matrix and fill with ones certain positions
651 Solvers
More from this Author17
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!