Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Solve In Matlab Please..... A Fibonacci sequence is composed of elements by addi

ID: 3574598 • Letter: S

Question

Solve In Matlab Please.....

A Fibonacci sequence is composed of elements by adding the two previous elements. The simplest sequence starts with 1, 1 and proceeds as follows: 1, 1, 2, 3, 5, 8, 13, . However, Fibonacci sequences can be created with any two starting numbers. Prompt the user to enter the first two starting numbers in a Fibonacci sequence and the total number of elements requested for the sequence. Limit the number of elements in the sequence to 30 or less. If the user inputs a number for elements in sequence greater than 30, output an error message and ask the user to reinput a number less than or equal to 30. Find the sequence and store in an array of by using a for loop. Now plot your results in a bar graph. Find the sequence and store in an array of by using a while loop. Now plot your results in a horizontal bar graph.

Explanation / Answer

num1 = input('Enter first number: ');
num2 = input('Enter second number: ');

while true
    count = input('Enter number of elements in sequence: ');
    if count > 30
        printf('Number of elements in sequence should be <= 30. Try again.. ')
    else
        break;
    end
end

arr = [num1 num2];
for i = 3:count
    arr(i) = arr(i - 1) + arr(i - 2);
end

arr2 = [num1 num2];
i = 3;
while i <= count
    arr2(i) = arr2(i - 1) + arr2(i - 2);
    i++;
end

bar(arr)
figure
bar(arr2)
figure

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote