






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







ME2016A, Spring 2004, Dr. Ferri Name: _____SOLUTION_______ Final Exam, April 27
This is a closed-book, and closed-notes exam. You are allowed to refer to a single, handwritten, 8.5x11inch sheet of paper.
Honor Pledge: On my honor, I pledge that I have neither given nor received any inappropriate aid in the preparation of this exam.
Signature
Problem 1: ( 5) _______________ Problem 2: (20) _______________ Problem 3: (12) _______________ Problem 4: ( 8) _______________ Problem 5: (20) _______________ Problem 6: (15) _______________ Problem 7: (10) _______________ Problem 8: (10) _______________ Total: (100) _______________
Consider a linear programming problem
z = 2x1 + x
(a) Find any set of inequality constraints that forces the maximum of z to occur at the point x1 = 5,
x2 = 4.
(b) Give the line(s) of code necessary for linprog to find the maximum of z, and given the inequality constraints that you proposed in part (a).
Solution
The simplest choice would be two inequalities:
x 1 (^) ≤ 5 , x (^) 2 ≤ 4
2
1 x
x
. This gives the rectangular feasible region shown below,
and shows that the maximum value of z is 14.
Other possibilities: x 1 (^) ≤ 5 , 0. 5 x 1 + x 2 ≤ 6. 5
x 1 (^) + x 2 ≤ 9 , x 1 + 3 x 2 ≤ 17 2 x 1 (^) + x 2 ≤ 14 , x 2 (^) ≤ 4 <---- Not a good choice! 1st constraint parallel to contour!
x
x
1 2 3 4 5 6
1
2
3
4
Z=4 Z=8^ Z=
part (b):
A = [1 0; 0 1] B = [5; 4] f = [-2 ; -1] x = linprog(f,A,B)
or add LB = [0 0]’; UB=[Inf Inf]; x = linprog(f,A,B,[],[],LB,UB)
(c) Matlab lines:
x=[-1 0 1 2]' y=[0 2 0 1]' a=polyfit(x,y,1)
where a = [ a 1 a 0 ], reverse order from part (b)
(d) t
t r S
r
1
i =
y N yi
y − y =[ − 3 / 4 5 / 4 − 3 / 4 1 / 4 ]
i
St yi y
i
Sr yi yi
y ˆ^ [ X ]{ a }
y y ˆ , Sr = 0. 36 + 1. 69 + 0. 64 + 0. 01 = 2. 70
r =
(e) Since r^2 <<1, the fit is very poor
Consider the signal y(t) = cos(2*t). The signal is sampled with N points over a time interval of duration T seconds. The process is repeated with 6 different combinations, with the results displayed in the figures below. The combinations are:
(a) N= 64, T = 4pi (b) N= 64, T = 8pi (c) N=128, T = 4pi (d) N=128, T = 8pi (e) N=128, T = 10.5pi (f) N=128, T = 7.5pi
Match the N-T combination with the magnitude of the FFT in each figure below. (For clarity, write the value of N and T on each plot below.)
0 2 4 6
0
20
40
ω (rad/s)
abs(FFT)
0 2 4 6
0
20
40
ω (rad/s)
abs(FFT)
0 2 4 6
0
50
100
ω (rad/s)
abs(FFT)
0 2 4 6
0
50
100
ω (rad/s)
abs(FFT)
0 2 4 6
0
20
40
60
ω (rad/s)
abs(FFT)
0 2 4 6
0
20
40
60
ω (rad/s)
abs(FFT)
(a) N= 64, T = 4pi ω 0 = 1/2, Y 4 = N/2 = 32 (5th point) (b) N= 64, T = 8pi ω 0 = 1/4, Y 8 = N/2 = 32 (9th point) (c) N=128, T = 4pi ω 0 = 1/2, Y 4 = N/2 = 64 (d) N=128, T = 8pi ω 0 = 1/4, Y 8 = N/2 = 64 (e) N=128, T = 10.5pi ω 0 = .19, Y 10 ≈ 64 (peak spread out) (f) N=128, T = 7.5pi ω 0 = .27, Y 7 ≈64 (peak spread out more)
(f)
(a)
(b)
(c)
(d)
(e)
(a) Approximate the integral using rectangular integration and h = 0. (b) Using h = 0.1, use a combination of Simpson’s 1/3 rule and trapezoidal rule to obtain the most accurate estimate of the integral’s true value. (c) What is the order of error in h for the result of part (b); i.e., given that the error is
O(h p), what is p in this case? Explain your reasoning. (d) Give the line(s) of Matlab necessary to approximate the integral using the command trapz.
By inspection, we identify the following 6 points:
0 0 1 1 0.1 2 2 0.2 3 3 0.3 3 4 0.4 2 5 0.5 2
0.2 0.
0 x
f(x)
Note: midpoint-rule is not available because the function is assumed to be known only at the 6 given points.
(b) Since Simpson’s 1/3 rule is more accurate, we would want to use it for 4 of the 5 segments, and use trapezoidal for the remaining one. Note that it is impossible to apply Simpson’s 1/3 rule to the entire 5 segments! Let’s use Simpson’s 1/3 rule for the first 4 segments and trapezoidal for the last segment:
f f
h f f f
h f f f
h I ≈ + + + + + + +
(c) Composite application of Simpson’s 1/3 rule is accurate to order O(h4); a single application of
trapezoidal integration is accurate to order O(h3). Therefore, the O(h3) dominates.
(d) h=0.1; x=0:h:0.5; f=[1 2 3 3 2 2]; I = trapz(x,f); or: I = htrapz(f);*
Consider the initial value problem:
y dt
d y = − , y ( 0 )= 2 ;
(a) If a time step of h = 0.5 is used, what is the value of y at the end of two steps using 1st-order Euler integration. In other words, find y(1) using 1st-order Euler integration and h = 0.5. (b) Now, estimate y(1) using Heun’s method (2nd-order Runge-Kutta) with h = 0.5. (c) Assume that using n = 20 steps of 2nd-order RK gives a final value of y(1) = 0.75. When n = 40 steps of 2nd-order RK are used, the final value improves to y(1) = 0.74. Use Richardson extrapolation to combine the two results, yielding an even better estimate of the true value of y(1).
Solution
(a) First-order Euler Method: y (^) k + 1 = yk + f ( tk , yk ) h
y 1 = y 0 + f ( 0 , y 0 ) h = y 0 +(− y 0 ) h = 2 +(− 2 )* 0. 5 = 1
y 2 = y 1 + f ( h , y 1 ) h = y 1 +(− y 1 ) h = 1 +(− 1 )* 0. 5 = 0. 5
where k 1 (^) = f ( tk , yk ), k (^) 2 = f ( tk + h , yk + k 1 h )
iteration # tk yk Predictor, y0 k1^ k2^ phi^ yk+
1 0.0 2.00000 1.00000 -2.00000 -1.00000 -1.50000 1.
2 0.5 1.25000 0.62500 -1.25000 -0.62500 -0.93750 0.
(c) Richardson Extrapolation: RK2 is accurate to O(h^2 ) (globally), so:
y ( 1 )= y ( 1 ) h 1 + ch 12 = y ( 1 ) h 2 + ch 22 ⇒ 0. 75 + c ( 1 / 20 )^2 = 0. 74 + c ( 1 / 40 )^2 ⇒ c =− 16 / 3
y ( 1 )= 0. 74 − 16 /( 3 * 402 )= 222 / 300 − 1 / 300 = 221 / 300 = 0. 73666
or, using the result from trapezoidal integration, which is also O(h^2 ) accurate:
2 1 / (^4011) / 20
h = (^) h = y y y
Alternate version, incorporating feval and Heun’s iteration:
function [T,Y]=ode2_v2(fname,t_final,y0,h);
t=0; T=t; y=y0; Y=y;
while t < t_final fi = feval(fname,t,y); y0 = y + fih for i = 1:4; fip1=feval(fname,t+h,y0); phi=(fi+fip1)/2; y0=y+phih end y=y0; t = t+h; Y=[Y y]; T=[T t]; end
Y = Y(:); T=T(:); % convert to column vectors
Assume that the function ode2 that you wrote for problem 7 has been written, debugged, and works properly. Write a Matlab program (script of commands) that does the following:
Solution
[T,Y] = ode2(10,2,1);
t=0:0.01:10; ys = spline(T,Y,t);
plot(T,Y,'o',t,ys,'--');
xlabel('t') ylabel('y') legend('data','spline fit')
Produces the plot:
0 1 2 3 4 5 6 7 8 9 10 0
1
2
t
y
data spline fit