soln-x1

advertisement
W.R. Wilcox, 24 January 2004
Solution to the First Midterm Examination
ES 100, section 01. February 9, 2003
Closed book, closed notes. Solutions in bold.
Part 1: Following are commands in MATLAB language. Give their equivalents in usual algebraic
format.
a.
w = (2*z + 3*y^2)/(2*z^2 + 3*y)
w
b.
2z  3y 2
2z 2  3y
x = 5*b + 3*exp(a*b) / sin(pi2) / (c+4*d)
x  5b 
c.
3e ab
(Note that pi2 is a variable and not 2*pi or pi2)
sin( pi 2)(c  4d)
x = 1.08e-9 *a+ exp(sqrt(3 + 4*b^3*sin(2*pi)^2))
x  1.08x10 9 a  e
3 4b 3 sin2 ( 2 )
Part 2: Following are commands in algebra. Give their equivalents in MATLAB format with as
few parentheses as possible. Here, a, b & c are variables that have been given numerical values
previously, and x and y are vectors of length 5 (element by element computations are desired).
d.
bog  sin 2 ab 
3e a  1
a  2b c 2
bog = sin(a*b)^2+(3*exp(a)+1)/abs(a-2*b)/c^2
or bog = sin(a*b)^2+(3*exp(a)+1)/(abs(a-2*b)*c^2)
e.
fog 
sin(ln( 3x ))
3
sin( xy ) 3
cos(log( y ))
fog = sin(log(3.*x)*pi).*sin((x.*y).^3)./cos(log10(y.^3))
Part 3: Symbolic math. Write the symbolic commands required to determine the following.
f.
diff_f =
df
where f = e-axsin2(cx) (In class: a, c and x are variables, not as in part 2.)
dx
syms a c x
f = exp(-a*x)*sin(c*x)^2
diff_f = diff(f,x) (Although diff(f) works in this case, that is bad practice as variable is
not specified. Suppose, for example, you wanted to differentiate with respect to a
or c.)
3
g.
int_f =
 fdx where f is defined as above.
1
int_f = int(f,x,1,3)
Part 4: Matrices. Write the MATLAB commands to do the following using the shortest formats
possible.
h.
1
2
A
6

2





0  2  4
2
4
5
3
6
4
4
8
3
A = [1:4; 2:2:8; 6:-1:3; 2:-2:-4]
or in longer format: A = [1,2,3,4; 2,4,6,8; 6,5,4,3; 2,0,-2,-4]
i. Select the value in the third row and fourth column of A.
A(3,4) (ans = 3)
j. Make a new matrix B by using MATLAB to select the values in the second through fourth row
and second & fourth column of A.
B = A(2:4,[2,4])
B=
4
5
0
8
3
-4
or in longer format, B = A([2,3,4],[2,4])
Download