Sie sind auf Seite 1von 2

1. In our activity, bouncing balls. We want 8.

Consider the following MATLAB


to count upper right corner hits. Which function:
of these boolean conditions guarantees
function output = result( a, b )
that (1,1) is covered?
x = a*2 + b;
(i) x + r >= 1 && y + r >= 1
y = 2*a + 1;
(ii) x + y >= 2 - 2*r
output = [ x ; y ]
a. Neither c. Both
When a = 1 & b = 2, what is the value of
b. (i) only d. (ii) only
output?
2. Show the results generated by the
9. Show the results generated by the
following MATLAB command.
following MATLAB command when
a=8, b=6, & c=1.
y = [3.7 2.4; 0.3 5.2; 4.7 9.2];
maxy = max(y)
a = input('Enter a: ');
b = input('Enter b: ');
3. Given the following matrices, show the
c = input('Enter c: ');
results generated by these MATLAB
d = sqrt(b^2 - 4*a*c);
command
r1 = (-b - d)/(2*a)
r2 = (-b + d)/(2*a)
I = eye(2);
A = [1 2; 3 4];
10. What is the value of X and Y after the
A.*I
following script is executed:
.
X = 1;
4. Given the following matrix, show the
Y = 2*X;
results generated by these MATLAB
X = Y^2;
commands.
X = X - 1;
v = [1.2 3.8 8.5 5.1 4.7]
11. Show the results of X and Y generated
h = find (v>3.5)
by the following MATLAB command.
high = v(h)
Note: find ( ) output the indices.
X = 1;
Y = X;
5. Given the following matrix, show the
X = Y;
results generated by the MATLAB
X = 2*X;
command.
Y = Y/2;
R = [1.22 3.78 2.41]
12. What is the value of X and Y after the
fprintf('R = %3.1f \n', R) following script is executed:
6. What is the value of D after the
following MATLAB commands are X = 1; Y = 8;
executed: while X < Y
A = [ 1 2 ; 3 4 ]; if X < Y
B = [ 1 1 ; 1 1 ]; Y = Y/2;
C = A .* B; else
D = B * C; X = X/2;
end
7. Consider the following MATLAB end
function: 13. How many lines of output are produced
by the following script.
function output = midterm( r )
x = r(1); for k=50:70
y = r(2); if rem(k,2)~=0
z1 = x^2 + y^2; disp(k);
z2 = x; end
output = [ z1 ; z2 ] end

When r = [ 2 -1 ], what is the value of 14. Show the results generated by the
output? MATLAB command for n = 3 and
n=4.
while n>1 20. Show the results generated by the
disp(I dunno) MATLAB command:
if rem(n,2)==0
n = n/2; a = 1; b = 2; c = 3; d = 4;
else plot([a c],[b d])
n = 3*n+1;
end 21. Write a MATLAB command that
end generates 100 uniform random numbers
between -7 and +7?
15. Show the last line of output generated by
the following MATLAB command 22. Write a MATLAB program that plot the
function y = sin(x) across [0,2pi] but add
x = 1; random noise if
y = x; 2 4
x
while y==x && x<=4 && y<=4 3 3
x = 2*x
end

16. Show the results generated by the 23. Write the MATLAB commands to
following MATLAB command generate a table of conversions from
seconds to minutes. The range of
x = [10 20 30]; seconds should be from 0 to 60 min
y = [3 1 2]; increments of 3.
k = y(3)-1;
z = x(k+1) 24. Write a MATLAB function that accepts
time t as an input and returns a voltage
17. Given the function, then generate a plot of v = e-tcos(t).
function y = f(x)
x = x+1; 25. Write a MATLAB program that outputs
y = x+1; the velocity vs time graph and position
vs time graph of SHM.
Show the results generated by the
MATLAB command: 26. Write a MATLAB script that output the
same as linspace(1,5,5) ?
x = 1;
x = f(x+1); 27. Write a MATLAB command using the
y = x+1 built-in command linspace to produce
this array.
18. Show the results generated by the
MATLAB command and write x = [ 0 .25 .50 .75 1.00]
comments to this script:
28. Write a MATLAB script that will output
x = [ ]; a triangle.
for k=1:50
if floor(sqrt(k))==sqrt(k) 29. Write a MATLAB command using the
x = [x; k]; built-in command DrawStar to produce
end this figure:
end
x=x

19. Show the results generated by the


MATLAB command:

for k = 1:3
disp(I am)
k= 5;
disp(great)
end

Das könnte Ihnen auch gefallen