Can anyone suggest how to reduce the size of the code ?
Yes there are 2 ways. You can initialise f1 as a vector [1, 1]. You also don't need the if else statement if you use start i = 1:n and then use f1(i+2) = ...
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
n = 1;
f = 1;
assert(isequal(fib(n),f))
|
2 | Pass |
%%
n = 6;
f = 8;
assert(isequal(fib(n),f))
|
3 | Pass |
%%
n = 10;
f = 55;
assert(isequal(fib(n),f))
|
4 | Pass |
%%
n = 20;
f = 6765;
assert(isequal(fib(n),f))
|
Select every other element of a vector
16215 Solvers
What is the distance from point P(x,y) to the line Ax + By + C = 0?
209 Solvers
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
229 Solvers
Deleting an element in a matrix
242 Solvers
220 Solvers