CS101
Midterm Exam
July
6th, 2011
DO NOT START UNTIL INSTRUCTED TO DO SO. YOU
WILL LOSE POINTS IF YOU START WORKING ON THE TEST BEFORE WE TELL YOU. THIS IS A
75 MINUTE EXAM.
|
Name: |
|
Discussion Section: |
|
TA: |
|
FORM A |
· Use only a #2 pencil; otherwise, your exam won't be graded.
· Bubble in the Form Letter above!!! Bubble in your name and your NetID!!!
· Write your TA's name (of the section you attend) in the instructor slot and your section number in the section slot. Your section number is in the table provided at the bottom of this page.
· The exam consists of 8 pages (including this page). Check that your copy is complete, and ask for a replacement if it is not. Make sure you look at all the pages.
· You will have 75 minutes to FILL IN THE SCANTRON for the exam. You may not use any books, notes, or other references for this exam.
· NO QUESTIONS WILL BE ANSWERED DURING THE EXAM.
· At the end of the exam, stop writing and put down your pencil when time is called. Hand in both the scantron and all the pages of the exam booklet.
· NO CALCULATORS OR ELECTRONIC DEVICES OF ANY KIND ARE ALLOWED. TURN OFF CELL PHONES AND PAGERS. IF A CELL PHONE RINGS, DO NOT ANSWER IT!!
|
Time |
Tuesday-Thursday |
Monday-Wednesday |
|
9:00 am |
101-Arjun Rao |
|
|
10:00 am |
|
102-Steve Henry |
Note: Always choose one answer,
the most correct choice of the answers offered.
1.
What does Matlab return after the following commands are typed
in the Matlab command window?
>> clear
>> x = 4;
>> who
a) 4
b) error
c) x
d) Nothing appears
2.
What does Matlab return after the following commands are typed
in the Matlab command window?
>> x = ceil([1.9 3.4
-4.9 -5.3])
x
=
a) 2 4 4 5
b) 1 4 -4 5
c) 2 4 -5 -6
d) 2 4 -4 -5
3.
Given the matrix named
mat shown below,
>>
mat = [1 2 3 4;
4 3
2 1; 1 2
3 4; 4 3
2 1];
Select
the correct value Matlab returns when you type the following
expression in the Matlab command window.
>> mat(1:2:3,[1,3,4])
a)
1 3 4
4 2 1
1 3 4
b)
1 3
1 3
4 2
c)
1 3 4
4 3 1
d)
1 3 4
1 3 4
4.
What does Matlab return after the following command is typed
in the Matlab command window?
>> 2:3:7
a)
2
b)
2 3
c)
2 5
d)
2 5 7
5.
Given vectors v1, v2 :
>> v1 = [1; 2; 3];
>> v2 = [1 2 3];
which of the following is a legal
expression, that is, will NOT
produce a Matlab error?
a)
v1 + v2
b)
v1 – v2’
c)
v1 * v2’
d)
v1 .* v2
6.
Select one of the
following commands that plots a graph of the function y = sin(x) on the interval
[-20 , 20].
You may assume that the variable x has been assigned the following
values:
>> x
= linspace(-20,20,1000);
a)
>> plot(x, 'sin')
b) >> plot(x, sin(x))
c)
>> plot('sin')
d)
>> plot(sin(x))
7.
Select the Matlab function
that would correctly return the sum of the values of its two input parameters.
a)
function sum(y,z)
y + z;
b)
function x =
sum(y,z)
sum = y + z;
c)
function x =
sum(y:z)
x = y + z;
d)
function x = sum(y,z)
x = y + z;
8.
Select the value to
fill in the blank below to complete the Matlab expression to simulate the roll
of a single six sided die. Note the die values are 1,2,3,4,5,6 and are
integers.
>>floor( _____________________ * rand()) + 1
a)
3
b)
5
c)
6
d)
7
For
problems 9 and 10 use the following two vectors.
>> A =
[1,2];
>> B =
[3;4];
9. (True or False) The following operation will result in an error message when entered into the command window.
>> A.*B
10. (True or False) The following operation will result in an error message when entered into the command window.
>> A*B
11. (True or False) Given
>> x = linspace(0,2*pi,50);
The
following operation will result in an error message when entered into the
command window.
>> y = sin(x)
12. Given
>> s = [.1 3 -6 7 2 4 7];
>> r = [ 1 2 3 4 5 6 7];
Which of the following is a valid Matlab
command that will assign to z
the r values that
correspond to the largest value(s) in s? The answer
is z = [4 7].
a)
>>
z = r(s==max)
b)
>>
z = r(s==max(s))
c)
>>
z = r(s=max(r))
d)
>>
z = s(r==7)
13. Given a solvable linear system of equations represented by the relationship,
A*B=C
where A is a known coefficient
matrix with size NxN, B is an unknown vector with size Nx1, and C is an known
vector with size Nx1. Which of the following is the correct way to solve for
the vector B (assuming that B can be solved for).
a)
>>
B=A.^(-1)*C
b)
>>
B=C\A
c)
>>
B=A\C
d)
>>
B=C.\A
14. Given
>> y = [1 2 3 4 5 6 7 8]
Which of the following is a valid Matlab
command that will flip the values in y and assign them to the variable flipY? The answer is
>> flipY
=
8 7
6 5 4
3 2 1
a)
>>
flipY = y(end:-1:start)
b)
>>
flipY = y(end:1)
c)
>>
flipY = y(end:-1:1)
d)
>>
flipY = y(end:start)
15. What are the values of x after entering the following into the Matlab command window?
>> x = linspace(2,8,3)
a)
>>
x =
2 5
8
b)
The
above command will result in an error message.
c)
>>
x =
2 4
6 8
d)
>>
x =
2.0000
2.1429 2.2857 2.4286
2.5714 2.7143 2.8571
3.0000
16.
Which of the following Matlab command(s) is a correct way of
computing an approximation of the definite integral of the function f(x) = cos(x) on the real interval [0,
2π]?
a) >>
trapz(@x,'cos(x)',0,2*pi)
b) >> quadl(@cos,0,2*pi)
c) >> trapz('cos',[0,2*pi])
d) >> x =
linspace(0,2*pi,100)
>>
y = cos(x)
>>
quadl(x,y)
17.
Given
>> R = [1 2 3 4 5 6];
>> S = [3 7 1 9 2 5];
Which is the correct
way to plot R vs S with R on the horizontal axis and S on the vertical axis
using a dotted green line. (Note in Matlab a colon : denotes a dotted line and
the letter g denotes the color green)
a)
>>
plot(R,S,'g:')
b)
>>
plot(S,R,g:)
c)
>>
plot(S,R,g,:)
d)
>>
plot(R,S,'g',':')
18.
Given the code for the function named fun
shown below,
function y = fun(x)
y = x+5;
what does Matlab return after
the following command is typed in the Matlab command window?
>> fzero('fun',3)
a)
3
b)
8
c)
0
d)
-5
19.
Given the code for the function named fun1
shown below,
function [y,z] = fun1(x,y)
y = x+5;
z = y+3;
and the script shown below
saved in the file script1.m ,
x
= 3;
y = 4;
z = 5;
what does Matlab return after
the following commands are typed in the Matlab command window?
>> clear
>> x = 1;
>> y = 2;
>> z = 3;
>> script1;
>> [y,z] = fun1(x,y);
>> z
z =
___________?________________
a)
5
b)
9
c)
7
d)
11
20.
Given the code for the function named fun2
shown below,
function z = fun2(x)
global y
z = x+y+5;
what does Matlab return after
the following commands are typed in the Matlab command window?
>> clear
>> global y
>> y = 1;
>> y = fun2(0);
>> y = fun2(1)
y
= ____________?_________________
a)
6
b)
7
c)
12
d)
the
code produces a Matlab error