D. What Happens If V and W Are Not the Same Length?

D. What Happens If V and W Are Not the Same Length?

<p>Lab 6 CS2503 Branching</p><p>1. Given: v = [4, -2, -1, 5, 0, 1, -3, 8, 2] and w = [0, 2, 1, -1, 0, -2, 4, 3, 2]. Evaluate the following expressions without Matlab, and then check your answers with Matlab. Record your answers on this document: a. v >= w ______b. w ~= v ______c. v < w ______d. What happens if v and w are not the same length?</p><p>2. Write a program in a script file that determines the real roots of a quadratic equation a  x 2  b  x  c  0. Name the script quadroots. The script will prompt the user to enter the coefficients a, b, and c then computes any real roots if they exist.  Compute the discriminant D given by the equation: D  b 2  4  a  c  If D > 0, print “The equation has two real roots,” and print the two roots.  If D = 0, print “The equation has one real root,” and print the value of the root.  If D < 0, print “The equation has no real roots.”  Use a single if-block consisting of if, elseif, and else.  Run the script file in the command window three times to obtain solutions to the following three equations: o 2  x 2  8 x  3  0. roots = ______</p><p> o 15 x 2 10  x  5  0. roots = ______</p><p> o 18 x 2 12  x  2  0. roots = ______</p><p> Submit your completed script for this exercise to the lab instructor.</p><p>3. Write a function (not a script!) to compute worker pay. The function should have two inputs: hours worked and hourly wage. The function will compute and return the total pay based upon the following schedule: a. A worker earns total pay based on hours worked times the hourly wage for the first 40 hours worked. b. A worker earns double the hourly wage for hours worked above 40 hours up to 60 hours. c. A worker earns triple the hourly wage for hours worked above 60 hours.</p><p>Use one if-elseif-else block for your function and test it for the following inputs and pay = $25.25 per hour. 38 hours worked, total pay = ______47 hours worked, total pay = ______63 hours worked, total pay = ______Submit the completed script to the lab instructor. 4. The maximum daily temperature in Fahrenheit for New York City and Anchorage, Alaska are given for the month of January in order from the 1st to the 31st:</p><p>NYC = [ 31, 26, 30, 33, 33, 39, 41, 41, 34, 33, 45, 42, 36, 39, 37, 45, 43, 36, 41, 37, 32, 32, 35, 42, 38, 33, 40, 37, 36, 51, 50];</p><p>ANC = [ 37, 24, 28, 25, 21, 28, 46, 37, 36, 20, 24, 31, 34, 40, 43, 36, 34, 41, 42, 35, 38, 36, 35, 33, 42, 42, 37, 26, 20, 25, 31];</p><p>Write a script file using Matlab functions and operators to answer the following:</p><p> a. Calculate the average (mean) temperature for the month in each city (Matlab has a function for computing the mean, use help to find it).</p><p> b. How many days were below the average temperature in each city? </p><p> c. How many days, and which days of the month, was the temperature in Anchorage higher than the temperature in New York?</p><p> d. How many days, and which days of the month, was the temperature in both cities the same?</p><p> e. How many days, and which dates in the month, was the temperature in both cities above freezing (32F).</p><p>The Matlab functions mean, sum and find will be helpful with this assignment</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us