ITEC 2600 Study Guide - Quiz Guide: Binary Search AlgorithmExam
Course CodeITEC 2600
This preview shows half of the first page. to view the full 1 pages of the document.
ITEC2600 in-Class Exercises X.Zhou York University
Introduction to Analytical Programming
Lab Exercise ♯6
1. Redo all examples from the lecture.
2. Generate vectors v1, v2, v3and v4that contain 100,1000,10000,100000 random integers ranging between
201to 599 separately, ﬁnd all indices of key value of 399 in v1, v2, v3and v4using sequential and binary
search, and report the runtime in seconds.
3. –Write a function functions fnfnxy receives three input arguments: vector xand vector y, a function
handle fnhan, output the results calculated from function handle passed.
–Write an anonymous function for r=px2+y2, vectorizing your code.
–Write a script that call a function functions in a), given two vectors: v1 = [1 2 3 4 5] and
v2 = [9 4 5 3 8], and anonymous function in b).
–What will happen if you only have one input argument? You may try diﬀerent equations with one
or two or three variables.
4. 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 the WCF is
W CF = 35.7 + 0.6T−35.7(V0.16) + 0.43T(V0.16 )
(a) Write a user-deﬁned function that accept temperature and wind speed as two input argument and
compute WCF as output argument. Vectorizing your code.
(b) Write an anonymous function to implement above equation. Your function will take temperature
and wind speed as arguments, compute and return the WCF. Vectorizing your code.
(c) ‘DataFile.xls’ give simulated temperature(sheet1) and wind speed(sheet2) based on the historical
records of Toronto. In the DataFile.xls, please note that wind speed is measured in kilometer per
hour, temperature is measured in degrees Celsius, where 1km = 0.6214 mile, 10C= (10F−32)/1.8.
Write script that read the temperature and wind speed from DataFile.xls, convert temperature to
degree of Fahrenheit and wind speed to miles per hour, calculate WCF by calling the functions
you wrote in a) and b) for whole year. Which one(user-deﬁned function or anonymous function)
is more eﬃcient? Use tic/toc/timeit to record the execution time, and print out your conclusion.
Note:minimize the background processes.
You're Reading a Preview
Unlock to view full version