Plot Linear Equation vs Logarithmic Equation for Fibonacci's Sequence

2 ビュー (過去 30 日間)
Marisa
Marisa 2024 年 1 月 30 日
編集済み: Walter Roberson 2024 年 1 月 30 日
How Would you go about doing a Linear Plot for Fibonacci's Sequence with this code
with
n=10
Fib([1 1])
For loop created
for ind=3;n
Fib(ind) = Fib(ind - 2) + Fib (ind - 1);
end

回答 (1 件)

Rishi
Rishi 2024 年 1 月 30 日
Hi Marisa,
I understand from your query that you want to know how to plot Fibonacci sequence.
You can use the following code for that:
n = 10;
Fib = zeros(1, n);
Fib(1) = 1;
Fib(2) = 1;
% Generate the Fibonacci sequence
for ind = 3:n
Fib(ind) = Fib(ind - 2) + Fib(ind - 1);
end
% Create a linear plot of the Fibonacci sequence
plot(1:n, Fib, '-o');
ylabel('Fibonacci Number');
Alternatively, you can use the 'fibonacci' function from Symbolic Math Toolbox to generate the Fibonacci numbers.
n = 1:10;
fibonacci(n)
ans = 1×10
1 1 2 3 5 8 13 21 34 55
You can learn more about 'fibonacci' function from the below documentation:
Hope it helps!

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by