How to make a matrix of fibonacci values and the corresponding number of elements to get 5702887?

Making a matrix of fibonacci values and the corresponding number of elements to get 5702887? Using a while loop I am not sure where to begin. I was given that the output must be 5702887 and there should be 26-39 elements in the vector and that I must use a while loop

4 Comments

What have you done so far? Please post your code and ask specific questions about where you are having trouble and we can offer comments, advice, corrections, etc.
I am not sure where to begin. I was given that the output must be 5702887 and there should be 26-39 elements in the vector and that I must use a while loop.
Do you know how to calculate Fibonacci numbers? Do you know how to write a while loop? Do you know how to iteratively assign values to the elements of a vector in a loop? That is where to begin.
Yes I know how to calculate them and how a while loop works, I am just confused about the programming

Sign in to comment.

Answers (1)

last_generated = 0;
while last_generated < 5702887
generate another one
last_generated = generated value
end

1 Comment

Look at this example:
results = []; currentvalue = 0;
while currentvalue < 5
thisvalue = rand();
results(end+1) = thisvalue;
currentvalue = currentvalue + thisvalue;
end
length(results)

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 25 Nov 2015

Commented:

on 26 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!