How to make a matrix of fibonacci values and the corresponding number of elements to get 5702887?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
James Tursa
2015-11-25
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.
回答(1 个)
Walter Roberson
2015-11-25
last_generated = 0;
while last_generated < 5702887
generate another one
last_generated = generated value
end
1 个评论
Walter Roberson
2015-11-26
Look at this example:
results = []; currentvalue = 0;
while currentvalue < 5
thisvalue = rand();
results(end+1) = thisvalue;
currentvalue = currentvalue + thisvalue;
end
length(results)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!