Fall 2015
𝑙𝑜𝑔 (𝑒 )/ ln 2
a. log(exp(3))/log2
b. log10(e^3)/log(2)
c. log10*(exp^3)/log(2)
d. log10(exp(3))/log(2)
Answer:
𝑣 = [ _ _ _ ]
>>syms x
a. int(x^3*(cos(x))^2,2*pi,0)
b. int(x^3*(cos x)^2,0,2*pi)
c. int(x^3*cos^2 (x),0,2*pi)
d. int(x^3*cos(x)^2,0,2pi)
1 2 3
1 2 3
4. Given: D = 4 5 6 . Which command will extract the submatrix ?
4 5 6
7 8 9
a. D[1:2,1:3]
b. D(1,2 ;1,3)
c. [D(1:2),D(1:3)]
d. D(1:2,1:3)
5. Complete the Mtlab code that plots𝑦 = 𝑐𝑜𝑠(𝑥 )/𝑥 for ≤ 𝑥 ≤ 𝜋, using a dashed red line
MATLAB Exam1 Practice Fall 2015
x= linspace(____,____,20);
y=cos(x____)____x;
plot(x,y,’r___’)
6. The function below computes the areaA and volumeV of a cylinder given its radius and
height:
Which Matlab code calls function for input arguments r=3 and h=5:
a. [ ] = cylinderprop(3,5)
b. [A,V] = cylinderprop(5,3)
c. [A,V] = cylinderprop(3,5)
d. (A,V) = cylinderprop(3,5)
7. What Matlab command is used to clear all the variables and functions from the workspace?
a. clear workspace
b. clear all
c. close all
d. clc
𝟐𝒙 + 𝒚 = 𝟓;
𝒙 − 𝒚 = 𝟔;
syms____
eq1 = 2*x+y-5;
eq2 = ____________________;
9. Given the anonymous function f=@(x,y) x+y. For x=[1 2] and y=[1 0], find f([1 2],[1 0]).
syms____ ____
v = 3*p*t + 5*t^2;
subs( _________,[ ___ ___ ], [ ___ ___ ] );
𝒅𝟑
11. Use symbolic computation to Differentiate the following in MATLAB: 𝒅𝒙𝟑
𝟑𝒙𝟐 + 𝟗𝒆𝒙
syms x
a. diff(3x^2+9exp(x),3)
b. diff(3*x^2+9*exp(x),3)
c. diff^3(3*x^2+9*exp(x))
d. diff[3*x^2+9*exp(x),3]
a. 3*x.*y+x^2+x.*y
b. 3*x*y+x^2+x*y
c. 3*x*.y+x.^2+x*.y
d. 3*x.*y+x.^2+x.*y
( )
13. Write matlab commands to plot 𝑦 = + 𝑥 for 1 ≤ 𝑥 ≤ 3, using a solid black line and
( )
circles.
x=_______________________;
y=____________________________________;
plot___________________________________;
a. B <12x9 Double>
b. B <9x9 Double>
c. B <12x12 Double>
d. B <9x12 Double>
15. What is the name of the window in MATLAB where variables are stored?
a. Command Window
b. Workspace
c. Command History
d. Editor
MATLAB Exam1 Practice Fall 2015
16. For 2 equal-sized vectors x and z, which of these expressions is not properly vectorized?
a. y = x.*z + 8;
b. y = x^2 – 2/z;
c. y = 2*(z + x);
d. y = z/4 + 7*x;
17. Write the missing command lines that are used to create the plot of y=x*sin(x) below for :
A=1:2:10;
B=linspace(1,5,5);
C = length(A)*B(2)+A(5)*B(3);
a) 34
b) 35
c) 36
d) 37
−1 2 −3
19. Matrix A is defined: A = 0 2 4 Which command deletes the second row?
2 −2 3
a) A(2,:) = 0;
b) A(:,2) = 0;
c) A(2,:) = [ ];
d) A(:,2) = [ ];
MATLAB Exam1 Practice Fall 2015
a) dimension=size(a)
b) [r,c]=sizeof(a)
c) dimensions(A)
d) [r,c]=size(A)
23. Consider the following MATLAB command to plot y vs x .Which line gives an error message:
a) >> x=linspace(1,10,100)
b) >> y=x^2;
c) >> figure(1)
d) >> plot(x,y);
24. Find the answer for [x , y]=sample(3) for the function below:
a) [x , y] = [6, 18]
b) [x , y] = [9, 6]
c) [x , y] = [6, 9]
d) [x , y] = [18,9]
25. Using “subplot(m,n,p)” command create a figure window which will plot x ∙ sin(𝑥) and
cos(x+2), side by side in the same figure window. The vector 𝑥 ∈ [−𝜋, 𝜋], has 50 elements.
x=___________________________;
subplot(____________); _________________________
subplot(____________); _________________________
2𝑥 + 𝑥 − 𝑥 = 1
5𝑥 + 2𝑥 + 2𝑥 = −4
3𝑥 + 𝑥 + 𝑥 = 5
________
eq1=___________________;eq2=__________________;eq3_____________________;
_____________________________;
27. Plot the following functions on the same graph, showing only the legend for 0 ≤ 𝑥 ≤ 2𝜋:
𝑦 = 2𝑥 sin (𝑥/2) ( Blue squares); 𝑦 = 2𝑥cos (𝑥)(Green diamonds)
28. How can you solve sin x = x − 1 in matlab using symbolic computation?
syms ___; ____________________
29. What commands compute Y in for 5 linearly spaced points in the range 0≤k≤𝜋/2, given that:
𝑘 sinh 𝑘 + cosh 𝑘
𝑌= sech √𝑘 + 𝑘/5
𝑘
k=_________________________________;
Y=_____________________________________________________________;
30. Use Symbolic computation to write the single line command that:
a) evaluates ∫ 𝑥 sin 𝑥 𝑑𝑥
syms _____; ______________________________________
Answer Key
1. d
2. 𝑣 = [1 2 3]
3. d
4. d
5. x= linspace(pi/2, pi ,20);
y=cos(x.^2) ./x
plot(x,y,’r --’)
6. c
7. b
8. syms x y
eq1 = 2*x+y-5;
eq2 = x - y - 6;
9. d
10. syms p t
v = 3*p*t + 5*t^2;
subs ( v , [p t ], [2 1 ] );
11. b
12. d
13. x=linspace(1,3);
y=log(x)./(x.^2.*sin(2*x))+x ;
plot(x,y,'k-o')
14. a
15. b
16. b
17. x=linspace(-3*pi,3*pi);
y=x.*sin(x)) ;
plot(x,y,'r--s')
18. d
19. c
20. d
21. C=13
22. D=[ 5 18 ]
23. b
24. c
25. x=linspace(-pi,pi,50) ;
subplot(1,2,1) ; plot(x, x.*sin(x))
subplot(1,2,2) ; plot(x, cos(x+2))
26. syms x1 x2 x3
eq1=2*x1 + x2 - x3 -1; eq2=5*x1+2*x2 + 2*x3 + 4 ; eq3=3*x1 + x2 + x3 - 5 ;
[x1,x2,x3]=solve(eq1,eq2,eq3)
29. k = linspace(0,pi/2,5);
Y = ((k.*sinh(k) + cosh(k))./(1-k).^2).*(sech(sqrt(k))).^2 + (k/5).^(1/3)