Question

Write a MATLAB script file that will sum all the positive entries in V and stop...

Write a MATLAB script file that will sum all the positive entries in V and stop summing once the sum reaches or exceeds 20(while loop). An fprintf statement should be used to display the value for the sum to prove it has reached or exceeded 20, and the number of entries to reach this value should be displayed. V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7]

Reminder: don’t use the built-in function, sum. Use vector indexing

0 0
Add a comment Improve this question Transcribed image text
Answer #1
V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7]
total = 0;
i = 1;
while i <= length(V) && total < 20
    if V(i) > 0
        total = total + V(i);
        i = i+1;
    end
end
fprintf("Value of sum is %d and number of entries added is %d\n", total, i-1)
Add a comment
Know the answer?
Add Answer to:
Write a MATLAB script file that will sum all the positive entries in V and stop...
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
  • THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...

    THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such...

  • Write a script file that will compare entries in vector V to entries in vector M...

    Write a script file that will compare entries in vector V to entries in vector M and determine how many entries in V are greater than the same entry in M, equal to the same entry in M, and less than the same entry in M. For example, V(1) is 7 and M(1) is 6, thus for this entry, V is greater than M. V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7] M =...

  • MATLAB HW 11 problem using Switch Case and Input commands Write a script file that calculates...

    MATLAB HW 11 problem using Switch Case and Input commands Write a script file that calculates the cost of a movie tickets according to the following price schedule:                                                  Number of Tickets being purchased Time of Movie < =5 tickets 6 to 9 tickets >=10 tickets Afternoon $6 $30 + $5 for the number of tickets above 5 $50 + $4 for the number of tickets above 9 Weeknight $7 $35 + $6 for the number of tickets above 5...

  • MATLAB help! I have some MATLAB Assignment to do, the proffesor requires all the small parts...

    MATLAB help! I have some MATLAB Assignment to do, the proffesor requires all the small parts in order to get full credit. Help me out, thank you f LAB SECTION NAME HW6P3 (30 points) following are infinite series representations of the function, un pra i a script file HW6P3 that determines the value of the function from the sum of the series for a given value of x. The program (1 pt) must prompt the user to enter a value...

  • MATLAB Required!! Write a MATLAB program named whileadder, to nput a desired maximum value. Be sure...

    MATLAB Required!! Write a MATLAB program named whileadder, to nput a desired maximum value. Be sure it is one value only Compute a running total by ones Return as output the last integer that can be added before the total exceeds max For example, if input max 60, the output should 10, because 1+2+3+4+5+6+7+8+9+10 : 55 and adding 11 would make the sum > 60M max- 55, then the output would be 10. Your Function C Reset MATLAB Documentation function...

  • MATLAB : Practice-4 (Oct. 31/ Nov. 1) Seat No. Name: Solve the following problems and write...

    MATLAB : Practice-4 (Oct. 31/ Nov. 1) Seat No. Name: Solve the following problems and write in the answers in blue and the plot in the box. Save the file in a pdf format and submit the answer script file and the pdf file to E-Class. 1. Re-do the Sample Problem 6-11 (Flight of a model rocket), but with the following conditions. - 16N force during the first 0.2 second - Parachute open when the downward velocity reaches 25 m/s...

  • MATLAB Questions. I have a basic understanding of the tools for MATLAB, but do not know...

    MATLAB Questions. I have a basic understanding of the tools for MATLAB, but do not know how to create the code for these questions. Please show the entire code. 2. A paper cup shaped as a frustum of cone with R-14R1 is designed to have a volume of 25 cm Determine R1, R2 and the surface area, S, of the paper for cups with a height, h, of 1O cm. The volume of the cup, V, and the surface area...

  • This is a matlab HW that I need the code for, if someone could help me figure this out it would b...

    This is a matlab HW that I need the code for, if someone could help me figure this out it would be appreciated. The value of t can be estimated from the following equation: in your script file, estimate the value of π for any number of terms. You must ask the user for the desired number of terms and calculate the absolute error/difference between your calculation and the built-in MATLAB value ofpi. Display your results with the following message...

  • you are designing a matlab script that will function as an automated cash regisiter. the cash...

    you are designing a matlab script that will function as an automated cash regisiter. the cash register will recive two inputs,the price of an item in cents, and the amount of cents payed by the customer. the cash register will then dispense change using the highest denominations of currency available ranging from 1 dollar bill to a penny dollar = 100 cents quarter =25 cents dime= 10 cents nickel=5 penny=1 cent your program should ensure that the highest available denomiation...

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
ADVERTISEMENT