Kuwait University Dept. of Chemical Engineering Spring 2017/2018
Kuwait University Dept. of Chemical Engineering Spring 2017/2018
Kuwait University Dept. of Chemical Engineering Spring 2017/2018
1 ……… / 40
2 ……… / 35
3 ……… / 25
GOOD LUCK
Page 1 of 8
Term Exam Two Spring 2017/2018
Page 2 of 8
Term Exam Two Spring 2017/2018
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
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
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.
Page 6 of 8
Term Exam Two Spring 2017/2018
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)
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:
Page 8 of 8