Question

1) Write a short script with a for-loop which will output the first 10 numbers in the Fibonacci sequence. (O, 1, 1, 2, 3, 5, 8,.. ao = 0,a, = 1, a2-1, a,-2, , an = an-2 + an-1 By using MatLab please.
Best.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please give the thumbs up, if it is helpful for you!!. Let me know if you have any doubts.

f(1) = 0;
f(2) = 1;
disp(f(1));
disp(f(2));
for i = 3 : 10
f(i) = f(i-1) + f(i-2);
str = [num2str(f(i))];
disp(str)
end

Execute le®Embed demo.m Stdin f(1) = 0; 2 f(2) 1; 3 disp(f(1)); 4 disp(f(2)); 5 for i= 3:10 str [num2str(f(i))]; 8 disp(str)

Output:

I.lI Result soctave -qf --no-window-system demo.m 21 warning: function /demo.m shadows a core library function

Add a comment
Know the answer?
Add Answer to:
By using MatLab please. Best. Write a short script with a 'for-loop' which will output the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Flowcharts & for loops 1. Using a for loop, write a MatLab script to convert ounces...

    Flowcharts & for loops 1. Using a for loop, write a MatLab script to convert ounces to grams for 0 to 16 ounces, in 1-ounce increments. Present output in a table; label columns appropriately. 2. A Fibonacci sequence is composed of elements created by adding the previous 2 elements. The simplest Fibonacci sequence starts with 1, 1 and proceeds as follows: 1,1,2,3,5,8… Element 3 is the sum of elements 1 and 2 (1+1=2) Element 4 is the sum of elements...

  • Using MATLAB code only please! 4. Write a script which does the following (use a while...

    Using MATLAB code only please! 4. Write a script which does the following (use a while loop). a. Creates a random number b. Calculates the sum of random numbers selected, across all loop iterations c. Prints the number of random numbers (the number of loop iterations) which were required to add up to 20 (or more).

  • matlab Write a script using a loop that will take a vector (of any size) of...

    matlab Write a script using a loop that will take a vector (of any size) of numbers and remove all numbers that are between 5.0 and 9.0 and assign the remaining vector to a nevw variable. Example: A-[1,5,8,10,13,18.20,9,4,6,8] B-[1,10,13,18,20,4]

  • The following procedure can be used to determine the roots of a cubic equation a_3x^3 +...

    The following procedure can be used to determine the roots of a cubic equation a_3x^3 + a_2x^2 + a_1x + a_0 = 0: Set: A =a_2/a_3, B = a_1/a_3, and C = a_0/a_3 Calculate: D = Q^3 + R^2 where Q = (3B - A^2)/9 and R = (9AB - 27C - 2A^3)/54. If D > 0, the equation has complex roots. It D = 0, all roots are real and at least two are equal. The roots are given...

  • Write a MATLAB script, using either a single or nested for-loop, that will print the factorials...

    Write a MATLAB script, using either a single or nested for-loop, that will print the factorials for the numbers between 1 and 100 (inclusive). The factorial of n (n!) is the product of the positive integers less than or equal to n. For example: 3! = 3 * 2 * 1. For this question you cannot use the built-in MATLAB factorial function, but you can use other MATLAB functions if you wish. MATLAB code!MATLAB code!MATLAB code!MATLAB code!

  • Please solve this using matlab and type in the codes here The following data was obtained...

    Please solve this using matlab and type in the codes here The following data was obtained when the stopping distance d of a car on a wet road was measured as a function of the speed v when the brakes were applied: v (mi/h) 12.5 25 37.5 50 62.5 75 d (ft) 20 59 118 197 299 420 Use polyfit function to determine the coefficients of a quadratic polynomial d = a_2 v^2 + a_1 v + a_0 that best...

  • 3[20%] | Fibonacci numbers are the numbers in a sequence in which the first two ele-...

    3[20%] | Fibonacci numbers are the numbers in a sequence in which the first two ele- ments are 0 and 1, and the value of each subsequent element is the sum of the previous two elements: 0,,,2,3, 5, 8, 13, Write a MATLAB program in a script file that determines and displays the first 20 Fibonacci numbers.

  • USING MATLAB Write a script that uses: both a FOR loop and an IF structure. It...

    USING MATLAB Write a script that uses: both a FOR loop and an IF structure. It should be at least 15 lines long, make it do anything you want! The script should have at least 5 errors! It should not run when someone tries it. the ONLY comments on this code should be 2 lines at the start describing what it should do.

  • Hi please help with this program C++ language thanks Write a recursive solution to solve the...

    Hi please help with this program C++ language thanks Write a recursive solution to solve the Partition problem. Partition: Given a set A of n integers a, a, .....a., can you find a subset A_1 of integers such that the sum of the Integers in A_1 is half of the Sum of all the n Integers (that Is, sigma_alpha 1 A_1 a_i)? Input: 1.Number of integers of set A: n 2.n Integers: a_1 a_2, a_n. Output: Print out yes if...

  • Using print(), loops, conditionals, and classes write a script that outputs a Fibonacci sequence (every number...

    Using print(), loops, conditionals, and classes write a script that outputs a Fibonacci sequence (every number after the first two is the sum of the two preceding ones): 1, 1, 2, 3, 5, 8, 13,

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT