






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to various problems related to linear programming and numerical integration. It includes explanations of how to find the maximizing solution for a linear programming problem using graphical methods, the comparison of accuracy between midpoint rule, rectangular integration, and trapezoidal rule, and the implementation of a multi-segment midpoint rule to evaluate the integral of a function using matlab.
Typology: Exams
1 / 11
This page cannot be seen from the preview
Don't miss anything!







ME2016A, Spring 2005, Dr. Ferri Name: _____ SOLUTION __________ Final Exam, May 5
This is a closed-book, and closed-notes exam. You are allowed to refer to a single, handwritten, 8.5x11inch sheet of paper. Although you can use a calculator, you must show all of your work in order to receive credit. Explain your reasoning if you wish to receive partial credit.
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: (10) _______________ Problem 2: (20) _______________ Problem 3: (10) _______________ Problem 4: (30) _______________ Problem 5: (10) _______________ Problem 6: (10) _______________ Problem 7: (10) _______________ Total: (100) _____ 100 _______
Problem 1. (10 points) Consider the linear programming problem:
Maximize z = x1 + x2 (1.1)
subject to x 1 (^) ≤ 4 (1.2) x 2 (^) ≤ 4 (1.3) px 1 (^) + x 2 ≤ 6 (1.4)
and the positivity constraints x 1 (^) ≥ 0 , x 2 (^) ≥ 0. Use the graph below to answer parts (a) – (c).
(a) Find the maximizing solution for p = 0.5 x 1 = 4, x 2 = 4, z = 8 (b) Find the maximizing solution for p = 1.0 line of possibilities, z = 6 (c) Find the maximizing solution for p = 2.0 x 1 = 1, x 2 = 4, z = 5
(d) Write a few lines of Matlab using linprog to give x when p = 2.
Two possibilities:
» LB = [0; 0]; UB = [4; 4]; A = [2 1]; B = 6; » f = -[1; 1]; x = linprog(f,A,B,[],[],LB,UB) or » A = [1 0; 0 1; 2 1]; B = [4; 4; 6]; f = [-1; -1]; » x=linprog(f,A,B)
2 4 6 8
2
4
6
8
p = p = 2 p = 0.
Line of optimal solns for p = 1
optimal soln for p = 0. optimal soln for p = 2
z = 1
contour line
(b) Here is one possibility:
function I = midpt_int(a,b,n); h = (b-a)/n; x = (h/2):h:(b-h/2); f = sin(x); I = sum(f)h;*
(c) Since the single-segment application of the midpoint rule is O(h^3 ), the multi-segment implementation would be “n-times larger,” or O(h^2 ). Thus, doubling n should reduce the truncation error by a factor of 4.
(d) I = I 1 + c (1/100)^2 = I 2 + c (1/200)^2. Let d = c/100^2. Then
I 1 + d = I 2 + d/4 Æ d = 4(I 2 – I 1 )/
I = I 2 + d/4 = (4/3) I 2 – (1/3) I 1
Problem 3. (10 points) Consider the first-order differential equation:
xy 0 dx
dy (^) + = ; y(0) = 1 (3.1)
Rather than solving this problem through use of a Runge-Kutta approach, we wish to solve it using finite-differences. The first-forward difference for dy/dx at a location xi can be expressed as:
h
y y dx
dy (^) i i xi
Using equations (3.1) and (3.2), write the linear system of equations in terms of h that will yield the values of y 1 through y 5. Determine if the solution to this system of equations is the same as that obtained with 1st-order Euler integration. (You do not need to actually solve for yi in order to make this determination, but explain your reasoning).
y(x)
h h h h h
y 1 y 2
y 4 y 5
y 3
x x 0 x^1 x 2 x 3 x 4 x (^5)
Substituting (3.2) into (3.1) at xi yields (yi+1 – yi )/h + xi yi = 0, i = 0, 1, 2, 3, 4
Recognize that xi = (i – 1)h, and y 0 = 1 gives the following system of equations:
i = 0: (y 1 – 1)/ h + 0 = 0 Æ y 1 = 1
i = 1; (y 2 – y 1 )/h + h y 1 = 0 Æ y 2 = y 1 – h^2 y 1
i = 2; (y 3 – y 2 )/h + 2h y 2 = 0 Æ y 3 = y 2 – 2h^2 y 2
i = 3; (y 4 – y 3 )/h + 3h y 3 = 0 Æ y 4 = y 3 – 3h^2 y 3
i = 4; (y 5 – y 4 )/h + 4h y 4 = 0 Æ y 5 = y 4 – 4h^2 y 4
By inspection, these are EXACTLY the same equations that are produced by the 1st-order Euler integration method.
At x = 2, 2 = b 0 + 2b 1 + 2b 2
Soln gives b 0 = 1, b 1 = 1, b 2 = -0.5 Æ y = 1 + x – 0.5x(x-1)
(d) r^2 must be 1 because the fit is perfect
(e) Integral must be exactly the same as Simpson’s 1/3 rule, since Simpson’s 1/3 rule is derived assuming that the actual function connecting three adjacent points is a quadratic:
I = (1/3)(1 + 42 + 2) = 11/
(f) There are 2 segments, thus 2 cubics, each having 4 constants. Since we have 8 equations, we must have 8 unknowns.
Let the cubic over the first segment be y 1 (x) = a 1 + b 1 x + c 1 x^2 + d 1 x^3 and let the cubic over the second segment be y 2 (x) = a 2 + b 2 x + c 2 x^2 + d 2 x^3
Continuity and passage through knots:
y 1 (0) = 1 Æ a 1 = 0
y 1 (1) = 2 Æ a 1 + b 1 + c 1 + d 1 = 2
y 2 (1) = 2 Æ a 2 + b 2 + c 2 + d 2 = 2
y 2 (2) = 2 Æ a 2 + 2b 2 + 4c 2 + 8d 2 = 2
Continuity of slope at interior knot:
(dy 1 /dx)x=1=(dy 2 /dx)x=1 Æ b 1 + 2c 1 + 3d 1 = b 2 + 2c 2 + 3d 2
Continuous curvature at interior knot:
(d^2 y 1 /dx^2 )x=1=(d^2 y 2 /dx^2 )x=1 Æ 2c 1 + 6d 1 = 2c 2 + 6d 2
Natural spline condition, zero curvature at extremities:
(d^2 y 1 /dx^2 )x=0 = 0 Æ 2c 1 = 0
(d^2 y 2 /dx^2 )x=2 = 0 Æ 2c 2 + 12d 2 = 0
Problem 5. (10 points) The following Matlab code implements Heun’s method of integration for the equation:
− sin( y )= 0 dx
dy ; y ( 0 )= yinitial
The code performs 4 iterations of the corrector step, stores the results into vectors X and Y, and plots the results. Correct all mistakes of logic and syntax
yinitial = input('Enter yinitial ... '); h = input('Enter h ... '); xf = input('Enter xf ... ');
x=0; y=yinitial; X=x; Y=y;
while x < xf;
y0 = y - sin(y)*h; ykp1_new = y0;
for k=1 to 4;
ykp1_new = y + h*(sin(y) + sin(ykp1_old));
end
y = ykp1_new; X=[X x];
end
plot(Y,X,'o-') xlabel('x'); ylabel('y')
There are seven errors, corrected on the next page in red:
Problem 6. (10 points, 2 points each) An integer-number of periods of a simple, periodic function is adequately sampled (no aliasing) with N=64 points. The first 10 values of the FFT are given below. Answer the following questions based on the graphs below; i.e., based on the portion of the FFT shown. Note that the abscissa is the FREQUENCY IN HZ, not rad/s. (a) What is the fundamental frequency (in rad/s) of the sampled signal, ω 0? (b) In terms of a real-valued Fourier series, give numerical values for ak , k = 0, 1, 2, …
(c) In terms of a real-valued Fourier series, give numerical values for bk , k = 1, 2, …
(d) Give the values of Y 63 , and Y 64. (e) Assuming that the duration of the signal, T , is held constant, what is the smallest number of samples, N , such that aliasing does not occur?
0 1 2 3 4 5 6 7 8 9
0
50
100
Frequency (Hz)
Real(Y)
0 1 2 3 4 5 6 7 8 9
0
10
Frequency (Hz)
Imag(Y)
(a) f 0 = 1 Hz, so ω 0 = 2 π (b,c) Y 0 = 64, & N = 64, so a 0 = 1. Y 1 = -32, so a 1 = -1. Y 2 = -32i, so b 2 = 1. Y 3 = -32, so a 3 = -1. All other ak, bk k< 10 are zero. We don’t know anything about the coefficients for k>9. So , as far as we can tell, the actual signal is
y(t) = 1 – cos(2 π t) + sin(4 π t) – cos(6 π t)
(d) complex conjugates: Y 62 = conj(Y 2 ) = +32i, Y 63 = conj(Y 1 ) = -32. There is no Y 64. (e) The highest frequency seen is 3* ω 0 = 6 π. Nyquist freq = N ω 0 /2 > 6 π. Æ N > 6
Problem 7. (10 points, 5 points each) (a) A steam table gives enthalpy values for 10 equally-spaced temperatures. Your employee decides to interpolate between the tabulated values using a 9th-order polynomial. Is that a good plan? Why or why not.
Since there are 10 datapooints, a 9th-order polynomial can indeed be made to pass through every point. However, this is not a good idea because high-order interpolation functions are prone to wild excursions in-between the data points; i.e., Runge phenomenon. It would be better to use linear interpolation or a spline fit.
(b) A 2nd-order RK scheme is used to integrate from t = 0 to t = 100 seconds using h = 0.01. For the same problem, a 4th-order RK scheme is used with h = 0.02. Which scenario requires more function (derivative) evaluations? Which is more accurate? Explain your answer.
The RK4 algorithm requires 4 derivative evaluations (function calls) per time-step while the RK2 algorithm requires 2. On the other hand, the time-step for the RK4 is twice as large as for RK2, so both scenarios require the same number of function calls. The global error of the RK2 technique is O(h^2 ) = O(0.0001). The global error of the RK4 technique is O(h^4 ) = O(0.00000016). Thus in theory, the RK4 technique should be more accurate by a factor of 625.