Question

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.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

% the function displays the fibonacci series of n numbers

% so, the series will look like 0, 1, 1, 2, 3, 5, ...

n = enter('Enter a number : ')

a = 0;

b = 1;

printf('a : ', a);

printf('b : ', b);

for i = 1 to n

{

    c = a + b;

   

    printf('b : ', b);

   

    a = b;

    b = c;

}

Add a comment
Know the answer?
Add Answer to:
USING MATLAB Write a script that uses: both a FOR loop and an IF structure. It...
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
  • Problem 2. Write a MATLAB script that uses nested loop statements to print the following multiplication...

    Problem 2. Write a MATLAB script that uses nested loop statements to print the following multiplication table. 4 8 12 16 5 10 15 20 25

  • 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!

  • Question 2 Problem Definition Write a MATLAB script that uses nested loops to create a 100 by 100...

    Question 2 Problem Definition Write a MATLAB script that uses nested loops to create a 100 by 100 element 2D array representing an image that shades from white at the top to black at the bottom. Your script should save the image in a file called test2.png. Testing The image file produced should be shaded from white at the top of the image to black at the bottom of the image like SO: Coding Write your code in a MATLAB...

  • Write a matlab script(using only matlab) for this. Write a script to solve the following problem:...

    Write a matlab script(using only matlab) for this. Write a script to solve the following problem: Ask the user for the length and the width of a rectangle. These need to be passed to a function. The function is to calculate and return the area and the perimeter of the rectangle. The area is the length times the width and the perimeter is 2 times the length and 2 times the width. Make sure to suppress all output from the...

  • Write a Matlab Function (not a script) that performs a single iteration of the Euler's method...

    Write a Matlab Function (not a script) that performs a single iteration of the Euler's method for the regular parashot problem, (i.e. just write a function that calculates v_next) Assume: cd = 0.25 [kg/m] for t < 10sec and cd = 1.5   [kg/m] for t ≥ 10sec Hint: use only if-statements, do not use any LOOPs you only need to compute only one iteration Hint2: make sure you define the inputs and outputs of the function correctly Please show how...

  • 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]

  • 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).

  • Question 2 (d) Write equivalent code to the one shown below by replacing the while loop...

    Question 2 (d) Write equivalent code to the one shown below by replacing the while loop with a for loop while x <= 15 x=x+1; end [4 marks] (e) Write the small program from the previous question using a single line of code with vector operations. [2 marks] (f) Write a MATLAB script that uses a loop to print the contents of two vectors interleaved in to one vector. Assume both vectors are the same length. For example, if A...

  • By using MatLab please. Best. Write a short script with a 'for-loop' which will output the...

    By using MatLab please. Best. Write a short script with a 'for-loop' which will output the first 10 numbers in the Fibonacci sequence. (0, 1, 1, 2, 3, 5, 8, ...) a_0 = 0, a_1 = 1, a_2 = 1, a_3 = 2, ..., a_n = a_n-2 + a_n-1

  • 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...

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