14:440:127 Introduction to Computers for Engineers
Recitation 12
 Problems for students to attempt
1.
Plotting
Over the past 5 years, the number of students in some Computer Vision class has been
15, 25, 55, 115, 144. Class size seems like it
ʼ
s growing exponentially. To verify this, plot
these values on a plot with a log y scale and label it (
semilogy, xlabel, ylabel, title
).
Use magenta square symbols of
marker size
10 and
line width
4, and no line
connecting them. (marker size and line width are both properties that you can change
direction in a line of code  type in
help plot
to see examples.) You may have to change
the x limits to see all 5 symbols (
xlim
). If the relationship really is exponential, it will look
linear on a log plot.
2. Function
Make function Mfile called
myLoopTest
(N)
that loops through the values 1 through N
and for each number n it should display
ʻ
n is divisible by 2
ʼ
,
ʻ
n is divisible by 3
ʼ
,
ʻ
n is
divisible by 2 AND 3
ʼ
or
ʻ
n is NOT divisible by 2 or 3
ʼ
. Use a for loop, the function mod or
rem to figure out if a number is divisible by 2 or 3, and num2str to convert each number
to a string for displaying. You can use any combination of if, else, and elseif.
3. System of Equations
Solve the following system of equations. Compute and display the error vector, which is
A*(your findings)  b.
3a + 6b + 4c = 1
a + 5b = 2
7b + 7c = 3
4. Fitting Line to Data
Write a script to
load
the data file
myRandData.mat
(which contains variables
x
and
y
)
and fit first, second, third, fourth, and fifth degree polynomials to it. Plot the data as blue
dots on a figure, and plot all five polynomial fits using lines of different colors and
increased widths. on the same axes. (line width is a property that you can change
direction in a line of code  type in
help plot
to see examples.) Label the figure
appropriately. To get good fits, you
ʼ
ll have to use the centering and scaling version of
polyfit
(the one that returns three arguments, see
help
) and its counterpart in
polyval
(the one that accepts the centering and scaling parameters).
Your script should generate the figure below:
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
5. Plotting
Make a vector of 10 random values and plot them on a bar graph using red bars,
something like the figure below.
6. Structures
Structures are useful in many situations when dealing with diverse data. For example,
get the contents of your current directory by typing
a=dir;
a.
a
is a structure array. What is its size? What are the names of the fields in
a
?
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 Finch
 $1000, 0.5%, polyval

Click to edit the document details