Вы находитесь на странице: 1из 8

Term Exam Two Spring 2017/2018

Kuwait University Spring 2017/2018


Dept. of Chemical Engineering

ENG 307 – Applied Numerical Methods and Programming


in Engineering

2nd May 2018 Term Exam Two Duration: 90 minutes

Name: ____________________________ ID: ________________

Question Score / Points

1 ……… / 40

2 ……… / 35

3 ……… / 25

Total ……… / 100

GOOD LUCK

Page 1 of 8
Term Exam Two Spring 2017/2018

Problem One: (40 Points)


The following system of equations is designed to determine concentrations (the c’s
in g/m3) in a series of coupled reactors as a function of the amount of mass input to
each reactor:
−3𝑐𝑐1 + 18𝑐𝑐2 − 6𝑐𝑐3 = 1050
−4𝑐𝑐1 − 𝑐𝑐2 + 12𝑐𝑐3 = 2275
15𝑐𝑐1 − 3𝑐𝑐2 − 𝑐𝑐3 = 4250
Actual concentrations in the reactors are: c1 = 250, c2 = 225, c3 = 325 g/m3.
10 a) Rearrange the equations, if necessary, to achieve convergence, represent them in matrix
form ([𝐴𝐴]{𝐶𝐶} = {𝐵𝐵}), define the system of equations in MATLAB, and write the
statement for solving them using matrix operations (inv and/or backslash \).
Equ. 1: 15𝑐𝑐1 − 3𝑐𝑐2 − 𝑐𝑐3 = 4250
15 −3 −1 𝑐𝑐1 4250
5 Equ. 2: −3𝑐𝑐1 + 18𝑐𝑐2 − 6𝑐𝑐3 = 1050 �
2 −3 18 −6 � × �𝑐𝑐 2 � = �1050�
−4 −1 12 𝑐𝑐3 2275
Equ. 3: −4𝑐𝑐1 − 𝑐𝑐2 + 12𝑐𝑐3 = 2275
>> A = [15 -3 -1;-3 18 -6;-4 -1 12];
3 >> B = [4250;1050;2275]; % B is a column vector
>> x = A\B; or x = inv(A)*B; % B’ if B is a row vector
b) Show two complete iterations of the Gauss-Seidel iterative method with
15
relaxation (λ = 0.75), starting from initial guesses of 𝑐𝑐10 = 𝑐𝑐20 = 𝑐𝑐30 = 200 g/m3.
2 2 2
Calculate the true errors (𝑒𝑒𝑡𝑡1 , 𝑒𝑒𝑡𝑡2 , 𝑒𝑒𝑡𝑡3 ) of the second iteration.
I 𝑐𝑐1 𝑐𝑐1𝑟𝑟 𝑐𝑐2 𝑐𝑐2𝑟𝑟 𝑐𝑐3 𝑐𝑐3𝑟𝑟
0 200.0000 200.0000 200.0000
1 336.6667 302.5000 175.4167 181.5625 305.5469 279.1602
2 338.2565 329.3174 206.2729 200.0953 316.0304 306.8128
2
𝜀𝜀𝑡𝑡1 = 5.9093
2
𝜀𝜀𝑡𝑡2 = 11.0687
2
𝜀𝜀𝑡𝑡3 = 5.5960

Page 2 of 8
Term Exam Two Spring 2017/2018

10 c) Write MATLAB script to solve the system of equations using 20 iterations of


the Gauss-Seidel iterative method, starting from initial guesses of 𝑐𝑐10 = 𝑐𝑐20 =
𝑐𝑐30 = 200 g/m3.

5 d) Write MATLAB statement that calls the function GaussSeidel for solving the system
of equations to an accuracy of εs = 1×10-8 and without exceeding 20 iterations.
>> A = [15 -3 -1;-3 18 -6;-4 -1 12];
>> B = [4250;1050;2275];
>> c = GaussSeidel(A,B,1e-8,20)
>>

Page 3 of 8
Term Exam Two Spring 2017/2018

Problem Two: (35 Points)


As shown in the Figure, moving away from the telecommunication radio tower,
results in the signal power (𝑃𝑃) received at our mobile phones to decrease
exponentially. The fade out of the signal can be represented by the following model:
𝑃𝑃 = 𝛼𝛼𝑥𝑥 −𝛽𝛽
where, 𝑥𝑥 is the distance from the radio
tower, 𝛼𝛼 is the fading gain, and 𝛽𝛽 is the
path-loss exponent.
The parameters 𝛼𝛼 and 𝛽𝛽 change from one
location to another. We are interested in estimating the values of these parameters
for Khaldia. The power of the signals 𝑃𝑃 (watt) measured at different distances (km)
are given in the Table below:
𝑥𝑥 (km) 2 3 4 5 6 7 8 9 10 11 12
𝑃𝑃 (W) 1756 1048 544 383 375 172 147 128 131 151 131

5 a) Linearize the model and write it in a form for determining the values of 𝛼𝛼 and 𝛽𝛽 using
linear least-squares regression.
log 𝑃𝑃 = log 𝛼𝛼 − 𝛽𝛽 log 𝑥𝑥

10 b) Write a MATLAB script to determine and evaluate the linear regression system, and
determine the parameters, 𝛼𝛼 and 𝛽𝛽 , and the coefficient of correlation, r2.
>> d = 2:12;
>> P = [1756 1048 544 383 375 172 147 128 131 151 131];
>> X = log10(d);
>> Y = log10(P);
>> A = [length(d) sum(X);sum(X) sum(X.^2)];
>> B = [sum(Y);sum(X.*Y)];
>> a_b = A\B;
>> alpha = 10^a_b(1)
>> beta = a_b(2)
>> st = sum((P-mean(P)).^2);
>> sr = sum((P-alpha*d.^beta).^2);
>> r2 = (st - sr)/st

Page 4 of 8
Term Exam Two Spring 2017/2018

5 c) Write MATLAB statements to find the parameters 𝛼𝛼 and 𝛽𝛽 using the polyfit function.
>> a_c = polyfit(log10(d),log10(P),1);
>> alpha = 10^a_c(2)
>> beta = a_c(1)

5 d) Redo part (c) using the linregr function. Display the values of 𝛼𝛼, 𝛽𝛽 and r2 (use disp).
>> [a_d,r2] = linregr(log10(d),log10(P));
>> alpha = 10^a_d(2);
>> beta = a_d(1);

10 e) Plot the experimental data together with the linear and nonlinear fits. Your code
should result in the following figure (use subplot).

>> subplot(2,1,1)
>> plot(d,P,'r*',d,alpha*d.^beta)
>> xlabel('x, km'); ylabel('P, watt')
>> title('Nonlinear Fit')
>> grid on
>> subplot(2,1,2)
>> plot(log10(d),log10(P),'r*',log10(d),a_c(1)*log10(d)+a_c(2))
>> xlabel('log_{10}(x), km'); ylabel('log_{10}(P), watt')
>> title('Linear Fit')
>> grid on

Page 5 of 8
Term Exam Two Spring 2017/2018

Problem Three: (25 Points)


Consider the telecommunication radio tower example given in Problem Two. For a mobile
phone moving away from the radio tower at a constant speed of v = 1 km/hr, the
total energy (E) received over the travelled distance is given by:
𝐹𝐹 𝑃𝑃
𝐸𝐸 = ∫𝑆𝑆 𝑑𝑑𝑑𝑑 (Whr)
𝑣𝑣

where S and F are the distances from the


radio tower, at which the mobile started
moving and stopped moving, respectively. 𝑬𝒏𝒆𝒓𝒈𝒚 E
Mobile Phone
In other words, energy received is the area
Radio Tower 𝐷𝑖𝑠𝑠𝑡𝑎𝑎𝑛𝑛𝑐𝑐𝑒𝑒 𝑑𝑑
under the power curve between the S and
Start S Finish F
F locations as shown in the Figure.
𝑥𝑥 (km) 2 3 4 5 6 7 8 9 10 11 12
𝑃𝑃 (W) 1756 1048 544 383 375 172 147 128 131 151 131

The objective is to determine the total energy, E, for the distance from S to F from
the radio tower.
5 a) Compute the total energy, E, from S = 2 to F = 12 km, using Simpson’s rule for h =
∆x = 1.

n = 11 odd  Simpson’s 1/3


12 1
𝐸𝐸 = ∫2 𝑃𝑃𝑃𝑃𝑃𝑃 = {1756 + 4(1048 + 383 + 172 + 128 + 151) +
3
2(544 + 375 + 147 + 131) + 131} = 3936.3
5 b) Write MATLAB statements to compute the total energy, E, from S = 2 to F = 12 km,
using the Trapezoidal rule for h = ∆x = 1.
>> d = 2:12; h = 1;
>> P = [1756 1048 544 383 375 172 147 128 131 151 131];
>> I_trap = h/2*(P(1)+2*sum(P(2:end-1))+P(end))

Page 6 of 8
Term Exam Two Spring 2017/2018

10 c) Compute the total energy, E, from S = 2 to F = 10 km, using Romberg integration to


the highest possible accuracy.
10
𝐸𝐸 = ∫2 𝑃𝑃𝑃𝑃𝑃𝑃

O(h2) O(h4) O(h6) O(h8)


h = 8 I1,1 = 7548 I1,2 = 4516 I1,3 = 3539.6 I1,4 = 3652.6
h = 4 I2,1 = 5274 I2,2 = 3600.7 I2,3 = 3650.8
h = 2 I3,1 = 4019 I3,2 = 3647.7
h = 1 I4,1 = 3740.5

5 d) Compute the total energy, E, from S = 2 to F = 12 km, by calling the MATLAB


function trapz.
>> P = [1756 1048 544 383 375 172 147 128 131 151 131];
>> E = trapz(2:12,P)

Page 7 of 8
Term Exam Two Spring 2017/2018

Formula Sheet:
1. Linear Systems
 Gauss-Seidel with relaxation: 𝑥𝑥𝑖𝑖𝑛𝑛𝑛𝑛𝑛𝑛 = 𝜆𝜆𝑥𝑥𝑖𝑖𝑛𝑛𝑛𝑛𝑛𝑛 + (1 − 𝜆𝜆)𝑥𝑥𝑖𝑖𝑜𝑜𝑜𝑜𝑜𝑜
 GaussSeidel function: function x = GaussSeidel(a,b,es,maxit)

2. Curve Fitting – Least-squares Regression


𝑛𝑛 ∑𝑛𝑛𝑖𝑖=1 𝑥𝑥𝑖𝑖 𝑎𝑎0 ∑𝑛𝑛𝑖𝑖=1 𝑦𝑦𝑖𝑖
 Linear regression: � � × � 𝑎𝑎1 � = � �
∑𝑛𝑛𝑖𝑖=1 𝑥𝑥𝑖𝑖 ∑𝑛𝑛𝑖𝑖=1 𝑥𝑥𝑖𝑖2 ∑𝑛𝑛𝑖𝑖=1 𝑥𝑥𝑖𝑖 𝑦𝑦𝑖𝑖

 Coefficient of Determination:
𝑠𝑠 −𝑠𝑠
𝑟𝑟 2 = 𝑡𝑡 𝑟𝑟 𝑠𝑠𝑡𝑡 = ∑𝑛𝑛𝑖𝑖=1(𝑦𝑦𝑖𝑖 − 𝑦𝑦�𝑖𝑖 )2 𝑠𝑠𝑟𝑟 = ∑𝑛𝑛𝑖𝑖=1(𝑦𝑦𝑖𝑖 − 𝑎𝑎0 − 𝑎𝑎1 𝑥𝑥)2
𝑠𝑠𝑡𝑡
 polyfit p = polyfit(x,y,n)
 polyval y = polyval(p,x)
 linregr function [a,r2] = linregr(x,y)

3. Numerical Integration

 Trapezoidal Rule:

 Simpson’s 1/3 Rule:

 Simpson’s 3/8 Rule:


4 k −1 I j +1,k −1 − I j ,k −1
 Romberg Integration Formula: I j ,k =
4 k −1 − 1
 trapz & sumtrapz function: function z = trapz(x,y) function z = cumtrapz(x,y)

Page 8 of 8

Вам также может понравиться