0% found this document useful (0 votes)
3 views3 pages

Lab5 - Section 1

Lab #5 for EECS 1560 focuses on using loops in MATLAB. It includes three main questions: converting Celsius to Fahrenheit or Kelvin, calculating the wind chill factor based on temperature and wind speed, and computing the moving average of a dataset. Students are required to submit their work as a single M-file on eClass.

Uploaded by

kisla05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Lab5 - Section 1

Lab #5 for EECS 1560 focuses on using loops in MATLAB. It includes three main questions: converting Celsius to Fahrenheit or Kelvin, calculating the wind chill factor based on temperature and wind speed, and computing the moving average of a dataset. Students are required to submit their work as a single M-file on eClass.

Uploaded by

kisla05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EECS 1560 Introduction to Computing for Mathematics and Statistics

LAB #5 (Section 01): Loops in MATLAB

(Due: as posted on eClass)


Objectives:

 This lab explores the use of loops in MATLAB.

Submit your script in eClass.


https://eclass.yorku.ca/

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. open MATLAB on your desktop,


2. open a new “M-file” by selecting “HOME” in the toolbar, then click on “New Script”. Save the file
under your current directory. NOTE: the filename must be a single_word
3. select “PUBLISH” in the toolbar
4. click “Section with Title”
5. replace “SECTION TITLE” with your name and student number
6. replace “DESCRIPTIVE TEXT” with a brief description of this lab
7. go to the next line, click “Section”, enter “Question 1” after “%%”
8. go to a new line, now you can proceed to lab question 1
9. repeat step 7 and enter the new question number whenever you finish a lab question
10. include functions within a m.file, at the end of the script file.

Please complete all the exercises in ONE M-file.

Please Submit only ONE M-file.

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

Enter a temperature in degrees C: 1300


Error, temperature in degrees C must be between -1000 and 1000!
Enter a temperature in degrees C: 30.2

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:

WCF  35.7  0.6T  35.7V 0.16   0.43T V 0.16 

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

You might also like