Lab5 - Section 1
Lab5 - Section 1
You may submit files as many times as you like. The most recent submission overwrites all previous
submissions.
Please follow the steps below before you proceed to the lab exercises:
1|Page
EECS 1560 Introduction to Computing for Mathematics and Statistics
Lab questions:
QUESTION 1: [34]
Write a script that will prompt the user for a temperature in degrees Celsius in the range from -1000◦C to
1000◦C, and then an „F‟ for Fahrenheit or „K‟ for Kelvin. The script will print the corresponding
temperature in the scale specified by the user. If the user enters a temperature value in degrees Celsius that
is outside the above range, an error message will be displayed and the script will keep prompting the user
to enter a new value until a valid value is entered. For example, the output might look like this: (red
numbers or character indicate values or character entered by the user).
Do you want K or F? F
The temperature in degrees F is: 86.4
The format of the output should be exactly as specified above. The conversions are:
9
F C 32
5
K C 273.15
QUESTION 2: [33]
The wind chill factor (WCF) measures how cold it feels with a given air temperature T (in degrees
Fahrenheit) and wind speed V (in miles per hour). One formula for WCF is:
a) Write a local function to receive the temperature and wind speed as input arguments, and return the
WCF.
b) Then in your m-file, write the scripts that print a list showing wind chill factors for temperatures
ranging from -20 to 55 in steps of 5, and wind speeds ranging from 0 to 75 in steps of 5. In your file,
you should call the function you defined in a) to calculate each WCF. For example, the first few lines
of the output are shown below:
The WCF for a temperature of -20F and a speed of 0 miles per hour is: 23.700000
The WCF for a temperature of -15F and a speed of 5 miles per hour is: -27.829659
The WCF for a temperature of -10F and a speed of 10 miles per hour is: -28.117591
The WCF for a temperature of -5F and a speed of 15 miles per hour is: -25.676827
...
2|Page
EECS 1560 Introduction to Computing for Mathematics and Statistics
QUESTION 3: [33]
A moving average of a data set x = {x1, x2, x3, x4, x5,…, xn-1, xn } is defined as a set of averages of subsets of
the original data set. For example, a moving average of every two terms would be
½ *{x1 + x2, x2 + x3, x3 + x4, x4 + x5,…, xn-1 + xn}. Write a local function that will receive a vector as an
input argument, and will calculate and return the moving average of every two elements. The function will
also output an error message if there is only 1 element in the data set x. Remember to test your function in
your script.
For example, if x = {3, 4, 5, 6}, the function will return {3.5, 4.5, 5.5}
3|Page