Download 8 Problems on Computing in MATLAB - Exam | CS 1171 and more Exams Computer Science in PDF only on Docsity!
Georgia Institute of Technology
College of Computing
CS 1171 Computing for Engineers
Exemption Exam - Fall Semester 2006
A A A A A A A A
B B B B B B B B
C C C C C C C C
D D D D D D D D
E E E E E E E E
F F F F F F F F
G G G G G G G G
H H H H H H H H
I I I I I I I I
J J J J J J J J
K K K K K K K K
L L L L L L L L
M M M M M M M M
N N N N N N N N
O O O O O O O O
P P P P P P P P
Q Q Q Q Q Q Q Q
R R R R R R R R
S S S S S S S S
T T T T T T T T
U U U U U U U U
V V V V V V V V
W W W W W W W W
X X X X X X X X
Y Y Y Y Y Y Y Y
Z Z Z Z Z Z Z Z
↑ Print your prism ID (not your 900 number) in
the spaces provided, and shade the boxes of the
corresponding numbers and/or letters.
I hereby signify that this examination paper
contains my own work exclusively, and I have
neither given nor received inappropriate help
during the taking of this examination, in
compliance with the letter and spirit of the
Academic Honor Code of Georgia Tech.
Name (print):
Signature:
TA / Section: ____________________________
Prob. Poss.Pts EarnedPts LostPts by
(cover) - -
TOTAL 140
Please Note: failure to complete this front sheet
correctly will cost you 5% of your grade.
Academic misconduct (including - but not limited to - examples on the list below) could result in a zero score on
this examination, an “F” final grade in the course, and/or other disciplinary action:
- Failure to cooperate with or follow directions given by a proctor.
- Failure to stop writing when the allotted time is up (as reported by a proctor).
- Communication with anyone other than a proctor for ANY reason in ANY language in ANY manner.
- Sharing of ANYTHING (e.g. pencils, erasers, paper).
- Writing on paper that is not given to you by a proctor.
- Using cell phones, beepers, personal radios or music players, etc. during the exam.
- Using calculators (unless explicitly permitted) or hand-held computers during the exam.
- Using books or other reference material during the exam.
- Disruption of the exam setting.
Reference Section:
colormap – sets the color map for the current plot. diag(m) – returns the diagonal elements of the matrix m factorial(n) – returns n! find(m) – returns the indices of the non-zero elements of m getfield(a,att) – returns the value of field att in the structure a – equivalent to a.(att) image(x) - display the image from the matrix x. imread(filename) - returns a matrix representation of an image imwrite(picture, filename, ‘jpg’) – writes an image to a .jpg file interp1(x, y, x1) – linearly interpolates on the plot y vs x for the points in x isempty(here) – checks if here is null (usually represented by [], the empty vector ischar(a) – checks if a is of class char (a string) isempty(a) – checks if a is empty isfield(a,att) – checks if att is a field in the structure a isstruct(a) – checks if a is a structure legend(‘str1’,’str2’, … ‘strn’) – put a legend on the current figure. length(a) – largest dimension of a magic(n) – builds a n * n magic square max(a) – value and index of the max value in a mesh(x, y, z) – plot the surface defined by the x, y and z arrays with colored lines and white faces [xx, yy] = meshgrid(x, y) – compute the plaid from the x and y vectors min(a) – value and index of the min value in a mod(a, b) – the remainder when a is divided by b ones(rows, cols) – generate a matrix filled with 1 polyfit(x, y, n) – fits an nth order polynomial to the x-y data, returning the n+1 coefficients in descending order of power of x polyval(c, x) – evaluates the polynomial defined by the coefficients c (as above) at the points x rmfield(str, att) – removes a structure field setfield(str, att, value) – set a structure field – equivalent to str.(att) = value sin(th) – sin of the angle in radians size(a) – all the dimensions of a sort(v) – arranges the vector v in ascending numerical order spline(x, y, x1) – cubic interpolation on the plot y vs x for the points in x strcmp(s1, s2) – compares two strings and returns true if they are the same. struct(att,val, … ,att,val) – builds a structure with the given attribute/value pairs sum(a) – total all the elements in the array surf(x, y, z) – plot the surface defined by the x, y and z arrays with colored faces and black lines title(str) – titles the plot with the given string (x/y/z)label(str) – labels the plot axes with the given string [nums, txt, raw] = xlsread(filename) – read an Excel spread sheet zeros(rows, cols) – generate a matrix filled with 0
Problem 2 – Simple Functions [10 pts]
You are given an array containing the total amount of rainfall (in cm) reported to have fallen in Atlanta on each of the last 15 days:
rainfall = [3 1 0 -4 1 0.5 1.5 -1 2.5 1 -0.5 0 -2 0.5 -1.5]
There is obviously a problem with the rainfall reporting system, since it is an error to report a negative rainfall total.
You are asked to write a MATLAB function called avgRain that will take in an array of reported daily rainfall totals (the array you are given is one example) and return the average of ONLY the non-negative numbers (either positive or zero) in the list. You may assume that every array of reported daily rainfall totals contains at least one element.
function ans = avgRain(rainfall)
Problem 3 – Matching [20 pts]
Choose the most appropriate answer from the right column for each blank in the left column.
_____ Creates a vector given a starting point, ending point, and number of points. _____ Calls itself until it reaches the terminating condition. _____ Used to convert data from the time domain to the frequency domain. _____ Can contain non-homogeneous data types. _____ Can be searched in O(log N).
_____ The worst case efficiency of an algorithm. _____ Will run as long as the condition is true.
a. in-order b. big O c. colon d. BST e. function f. recursive function g. pre-order h. for loop i. post-order j. linspace k. binary tree l. while loop m. wavread n. fft o. script p. linked list q. vector r. imread s. cell array t. tree u. plot
Problem 5 – Recursion and Structures [20 pts]
A Linked List is either empty ([]), or a LLNode structure with two fields: data containing any object (in our case a Student structure), and next containing another Linked List. Write a function called llAverage that consumes a linked list of student structures and returns their average grade. One of the fields in the student structure has the name grade.
Hint : Try writing two recursive helper functions rather than trying to do this in one ugly recursive call. You must use recursion to solve this problem. Use of iteration ( for or while loops) will result in a grade of 0 for this problem.
function avg = llAverage(here)
% you code here …
Problem 6 – Numerical Methods and Plotting [20 pts]
Write a Matlab function called curvePlot that will consume the following three items
- A vector of x values data
- A vector of y values data
- a number signifying the order of the polynomial fit
This function will perform an n th^ order curve fit on the data and will create a plot with the following items:
- Points of the original data points marked by red o’s
- Points of new y-values calculated marked by blue x’s
- A green line connecting the original data point to the new point
For example, curvePlot([1 2 3 4 5 6 7], [2 3 5 8 13 17 19], 2) should produce this plot:
function curvePlot(x, y, n)
Problem 8 – Miscellaneous [20 pts]
- Which of the following are attributes of recursion. Circle all that apply. a. Calls itself. b. Has some kind of condition that the problem can reach every time. c. The input must get smaller. d. All of the above.
- Given a vector of coefficients a, mark the code fragments below that will evaluate the following function for a single value of x (not a vector): y = a(1) + a(2) * x + a(3) * x^2 + ... a(n) * xn-^.
a. polyval(x, a)
b. n = 1:length(a) a(n) * x.^(n-1)'
c. polyval(a, x).
d. polyval(a(end:-1:1), x).
- The file fred.jpg contains a JPEG image with 200 rows and 300 columns. After the following code is executed, which of the following are true? (Mark all that apply) pic = imread(‘fred.jpg’); [rows cols] = size(pic); pic(:,:,[1 3]) = 0; a. The picture is totally red. b. The picture is totally blue. c. rows contains the value 200. d. cols contains the value 300. e. None of the above.
- Circle all the answers that create a vector all of whose entries are equal to 2. a. TWOS = ceil(linspace(1.1,2)); b. TWOS = floor(2:0.33:3.2); c. TWOS = find([1 8 10 3 5] == max([1 8 10 3 5])); d. TWOS = find(mod([1 2 5 9 3],2) == 0); e. TWOS = ceil(linspace(1,2));