How would I make my for loop more accurate.

1 次查看(过去 30 天)
a = 0;
b = 1;
c = 0;
d = 1;
for k = 1:700
c = a + b;
a = b;
b = c;
d = [d c];
end
format long
d(700) %>>> 8.747081495575278e+145
fibonacci(700) %>>> 8.747081495575285e+145
I believe the function fibonacci(n) has the correct number.
How does the function fibonacci have a more accurate number?

回答(1 个)

Walter Roberson
Walter Roberson 2019-2-10
fibonnaci() is a function in the Symbolic Toolbox. It calculates the numbers as indefinite precision software integers, and then converts the result to double.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by