Professional Documents
Culture Documents
(CHE555)
NUMERICAL METHOD
ASSIGNMENT 3 & 4
PROGRAMME/CODE : EH220
SEMESTER :4
GROUP : EH2204B
LECTURER : MOHAMMAD JINDRA BIN ARIS
ASSIGNMENT 3
Question 1
State the criterion that must be fulfilled for the inverse matrix and Cramer’s Rule to work in solving
simultaneous linear equations.
Question 2
2x1 + x2 – x3 = 1
3x1 + x2 + x3 = 5
By using MATLAB
Command Window
>> A = [2 1 -1;5 2 2;3 1 1]
A=
2 1 -1
5 2 2
3 1 1
>> det(A)
ans =
To find X1
B=
1 1 -1
-4 2 2
5 1 1
>> det(B)
ans =
28
X1=determinant(B)determinatA
= 282
= 14
To find X2
D = [2 1 -1; 5 -4 2; 3 5 1]
D=
2 1 -1
5 -4 2
3 5 1
>> det(D)
ans =
-64
X2=determinant(D)determinatA
= -642
= -32
To find X3
E = [2 1 1; 5 2 -4; 3 1 5]
E=
2 1 1
5 2 -4
3 1 5
>> det(E)
ans =
-10
X3=determinant(E)determinatA
= -102
= -5
Thus,
X=14-32-5
3R1-
11/2-1/201-93111/2135 11/2-1/201-901/2-5/21/213-7/2
R1- R3÷(-2)
R3
11/2-1/201-900-21/21310 R3
11/2-1/201-90011/213-5
X3 = -5
X2 – 9X3 = 13
X2 – 9(-5) = 13
X2 = -32
Thus,
X=14-32-5
Question 3
a) State the convergence criteria for using Gauss-Seidel method in solving simultaneous linear
equations
Convergence criteria can be developed and sufficient conditions for convergence of two nonlinear
equations, u(x, y) and v(x, y), are
∂u∂x+∂u∂y<1 and
∂v∂x+∂v∂y<1
These criteria also apply to linear equations of the sort we are solving with the Gauss-Seidel method. For
example, in the case of two simultaneous equations, the Gauss-Seidel algorithm can be expressed as
ux1,x2=b1a11-a1a11x2
And
vx1,x2=b2a22-a2a22x1
The partial derivatives of these equations can be evaluated with respect to each of the unknowns as
∂u∂x1=0 ∂u∂x2=-a12a11
And
∂v∂x1=-a21a22 ∂v∂x2=0
a12a11<1 and
a21a22<1
In other words, the absolute values of the slopes must be less than unity to ensure convergence. This is
displayed graphically. Then,
a11>a12
And
a22>a21
That is, the diagonal element must be greater than the off-diagonal element for each row. The extension
of the above to n equations is straightforward and can be expressed as
aij>j=1j≠inai,j
Relaxation represents a slight modification of the Gauss-Siedel method and is designed to enhance
convergence.
After each new value of x is compiled using equation (a), that value is modified by weighted average
of the results of the previous and the present iterations:
xi=bi-a12x2-a13x3a11
x2=b2-a21x1-a23x3a22
x3=b3-a31x1-a32x2a33
xinew=λxinew-1-λxiold
For values λ from 1 to 2, extra weight is placed on the present value. In this instance, there is an
implicit assumption that the new value is moving in the correct direction towards the true solution but
at too slow rate. Thus, the added weight of λ is intended to improve the the estimate by pushing it
closer to the truth. Hence, this type of modification, which is called overrelaxation, is designed to
accelerate the convergence of an already convergent system. The approach is also called successive or
simultaneous overrelaxation or SOR.
The choice of proper value for λ is highly problem-specific and is often determined empirically. For a
single solution of a set of equations, it is often unnecessary. However, if the system under study is to
be solved repeatedly, the efficiency introduced by a wise choice of λ can be extremely important.
Good examples are the very large systems of partial differential equations that often arise when
modeling continuous variations of variables.
Question 4
A×X=C
Command Window
A=
10 2 -1
-3 -6 2
1 1 5
>> det(A)
ans =
-289
A1 =
27.0000 2.0000 -1.0000
>> det(A1)
ans =
-144.5000
>> X1 = det(A1)/det(A)
X1 =
0.5000
A2 =
>> det(A2)
ans =
-2312
>> X2 = det(A2)/det(A)
X2 =
A3 =
>> det(A3)
ans =
1.7340e+003
>> X3 = det(A3)/det(A)
X3 =
-6.0000
X=0.58-6
Question 5
The problem of two dimensional heat transfers can be solved using finite difference method. Usually, this
will result in a number of simultaneous linear equations that need to be solved for temperature node.
Solve the following simultaneous equations that resulted from finite difference method:
T2 + T3 + 1000 – 4T1 = 0
T1 + T4 + T5 + 500 – 4T3 = 0
T3 + T6 + T7 + 500 – 4T5 = 0
T2 + 2T3 + T6 – 4T4 = 0
T4 + 2T5 + T8 – 4T6 = 0
– 4T1 + T2 + T3 = – 1000
T1 – 4T3 + T4 + T5 = – 500
T3 – 4T5 + T6 + T7 = – 500
2T1 + T4 – 4T5 = – 500
T2 + 2T3 – 4T4 + T6 =0
T4 + 2T5 – 4T6 + T8 =0
2T5 – 9T7 + T8 = – 2000
2T6 + 2T7 – 9T8 = – 1500
Cramer’s Rule
Command Window
>> A = [-4 1 1 0 0 0 0 0; 1 0 -4 1 1 0 0 0; 0 0 1 0 -4 1 1 0; 2 0 0 1 -4 0 0 0; 0 1 2 -4 0 1 0 0; 0 0 0 1 2 -4 0
1; 0 0 0 0 2 0 -9 1; 0 0 0 0 0 2 2 -9]
A=
-4 1 1 0 0 0 0 0
1 0 -4 1 1 0 0 0
0 0 1 0 -4 1 1 0
2 0 0 1 -4 0 0 0
0 1 2 -4 0 1 0 0
0 0 0 1 2 -4 0 1
0 0 0 0 2 0 -9 1
0 0 0 0 0 2 2 -9
>> det(A)
ans =
24172
A1 =
-1000 1 1 0 0 0 0 0
-500 0 -4 1 1 0 0 0
-500 0 1 0 -4 1 1 0
-500 0 0 1 -4 0 0 0
0 1 2 -4 0 1 0 0
0 0 0 1 2 -4 0 1
-2000 0 0 0 2 0 -9 1
-1500 0 0 0 0 2 2 -9
>> det(A1)
ans =
9548000
>> X1 = det(A1)/det(A)
X1 =
395.0025
A2 =
-4 -1000 1 0 0 0 0 0
1 -500 -4 1 1 0 0 0
0 -500 1 0 -4 1 1 0
2 -500 0 1 -4 0 0 0
0 0 2 -4 0 1 0 0
0 0 0 1 2 -4 0 1
0 -2000 0 0 2 0 -9 1
0 -1500 0 0 0 2 2 -9
>> det(A2)
ans =
4092000
>> X2 = det(A2)/det(A)
X2 =
169.2868
A3 =
-4 1 -1000 0 0 0 0 0
1 0 -500 1 1 0 0 0
0 0 -500 0 -4 1 1 0
2 0 -500 1 -4 0 0 0
0 1 0 -4 0 1 0 0
0 0 0 1 2 -4 0 1
0 0 -2000 0 2 0 -9 1
0 0 -1500 0 0 2 2 -9
>> det(A3)
ans =
9928000
>> X3 = det(A3)/det(A)
X3 =
410.7232
A4 =
-4 1 1 -1000 0 0 0 0
1 0 -4 -500 1 0 0 0
0 0 1 -500 -4 1 1 0
2 0 0 -500 -4 0 0 0
0 1 2 0 0 1 0 0
0 0 0 0 2 -4 0 1
0 0 0 -2000 2 0 -9 1
0 0 0 -1500 0 2 2 -9
>> det(A4)
ans =
8226000
>> X4 = det(A4)/det(A)
X4 =
340.3111
A5 =
-4 1 1 0 -1000 0 0 0
1 0 -4 1 -500 0 0 0
0 0 1 0 -500 1 1 0
2 0 0 1 -500 0 0 0
0 1 2 -4 0 1 0 0
0 0 0 1 0 -4 0 1
0 0 0 0 -2000 0 -9 1
0 0 0 0 -1500 2 2 -9
>> X5 = det(A5)/det(A)
X5 =
407.5790
A6 =
-4 1 1 0 0 -1000 0 0
1 0 -4 1 1 -500 0 0
0 0 1 0 -4 -500 1 0
2 0 0 1 -4 -500 0 0
0 1 2 -4 0 0 0 0
0 0 0 1 2 0 0 1
0 0 0 0 2 -2000 -9 1
0 0 0 0 0 -1500 2 -9
>> X6 = det(A6)/det(A)
X6 =
370.5113
A7 =
-4 1 1 0 0 0 -1000 0
1 0 -4 1 1 0 -500 0
0 0 1 0 -4 1 -500 0
2 0 0 1 -4 0 -500 0
0 1 2 -4 0 1 0 0
0 0 0 1 2 -4 0 1
0 0 0 0 2 0 -2000 1
0 0 0 0 0 2 -1500 -9
>> det(A7)
ans =
8438000
>> X7 = det(A7)/det(A)
X7 =
349.0816
>> A8 = [-4 1 1 0 0 0 0 -1000; 1 0 -4 1 1 0 0 -500; 0 0 1 0 -4 1 1 -500; 2 0 0 1 -4 0 0 -500; 0 1 2 -4 0 1 0
0; 0 0 0 1 2 -4 0 0; 0 0 0 0 2 0 -9 -2000; 0 0 0 0 0 2 2 -1500]
A8 =
-4 1 1 0 0 0 0 -1000
1 0 -4 1 1 0 0 -500
0 0 1 0 -4 1 1 -500
2 0 0 1 -4 0 0 -500
0 1 2 -4 0 1 0 0
0 0 0 1 2 -4 0 0
0 0 0 0 2 0 -9 -2000
0 0 0 0 0 2 2 -1500
>> det(A8)
ans =
7894000
>> X8 = det(A8)/det(A)
X8 =
326.5762
Thus,
➢ T1 = 395.0025
➢ T2 = 169.2868
➢ T3 = 410.7232
➢ T4 = 340.3111
➢ T5 = 407.5790
➢ T6 = 370.5113
➢ T7 = 349.0816
➢ T8 = 326.5762
ASSIGNMENT 4
Question 1
State the four assumptions required for the least squares method of regression to be valid
Answer:
a) Each x has a fixed value; it is not random and is known without error
b) The y values are independent random variables and all have the same variance
c) The y values for a given x must be normally distributed
d)
Question 2
Determine the best correlation (linear regression) for the prediction of boiling points of pure water at the
P = 0.5 atm up to water’s critical point. The regression must include residual analysis (e):
a) P = 0.5 atm, T = ?
P (atm) T (deg C)
0.5 81.6
1 100.0
10 180.5
20 213.1
30 234.6
40 251.1
50 264.8
60 276.4
70 286.7
80 295.9
90 304.3
100 312.0
110 319.1
120 325.7
130 331.9
140 337.7
150 343.2
160 348.4
170 353.4
180 358.1
190 362.6
200 366.8
210 370.9
From the graph, at P = 0.5atm
y = a0 + a1x + e
∑e=∑(yi-a0-a1xi)
And
a1=n∑xiyi-∑xiyin∑xi2-(∑xi)2
a0=y-a1x̅
= 1229.591955
Question 3
Using the steam table, perform the necessary multiple regression to predict the values of enthalpy of
superheated steam applicable for the following conditions:
Multiple R 0.991981985
R Square 0.984028259
Observations 49
Residual Output
PROBABILITY
Observat Predicted H Standard
Residuals OUTPUT
ion (kJ/kg) Residuals
H (kJ/kg)
1 2242.4825 933.3175 2.112919373 3164.3
727.117755
2 2551.482245 1.646107773 3166.3
1
522.318010
3 2860.48199 1.182465606 3168.2
2
319.218265
4 3169.481735 0.722672035 3170.1
3
117.818520
5 3478.48148 0.266727062 3172
4
-
6 3787.481224 81.8812244 -0.185369315 3173.9
9
-
7 4096.480969 279.880969 -0.633617094 3175.8
4
851.933214
8 2321.966786 1.928675069 3269.3
3
646.033469
9 2630.966531 1.462542632 3270.8
4
441.633724
10 2939.966276 0.999806017 3272.4
5
238.733979
11 3248.96602 0.540465223 3273.9
6
37.4342346
12 3557.965765 0.084746637 3275.5
9
-
13 3866.96551 162.165510 -0.367123351 3277
2
-
14 4175.965255 360.065255 -0.815144742 3278.6
1
770.548928
15 2401.451071 1.744430764 3375.2
6
565.049183
16 2710.450816 1.27920388 3376.5
7
360.849438
17 3019.450561 0.816920041 3377.8
8
158.149693
18 3328.450306 0.358032022 3379
9
-
19 3637.450051 42.9500510 -0.097233787 3380.3
2
-
20 3946.449796 242.449795 -0.548877387 3381.6
9
-
21 4255.449541 440.149540 -0.996446003 3382.8
8
689.164642
22 2480.935357 1.560186459 3482.3
9
23 2789.935102 483.964898 1.095638739 3483.4
280.065153
24 3098.934847 0.634034064 3484.5
1
77.5654081
25 3407.934592 0.175598822 3485.5
6
-
26 3716.934337 123.334336 -0.279214211 3486.6
7
-
27 4025.934082 322.634081 -0.730405035 3487.7
6
-
28 4334.933827 520.333826 -1.177973651 3488.7
5
607.780357
29 2560.419643 1.375942154 3590.9
1
402.980612
30 2869.419388 0.912299987 3591.8
2
199.380867
31 3178.419133 0.451374476 3592.7
3
-
32 3487.418878 2.91887755 -0.00660799 3593.6
1
-
33 3796.418622 203.718622 -0.461194635 3594.5
4
-
34 4105.418367 402.918367 -0.912159072 3595.4
3
-
35 4414.418112 600.418112 -1.359274911 3596.3
2
526.396071
36 2639.903929 1.191697849 3701
4
321.896326
37 2948.903673 0.728734846 3701.7
5
118.596581
38 3257.903418 0.268488499 3702.5
6
-
39 3566.903163 83.5031632 -0.189041191 3703.3
7
-
40 3875.902908 284.102908 -0.64317506 3704
2
-
41 4184.902653 483.202653 -1.093913108 3704.8
1
42 4493.902398 -680.602398 -1.540802559 3705.6
444.911785
43 2719.388214 1.007227156 3812.6
7
240.912040
44 3028.387959 0.545396093 3813.3
8
37.8122959
45 3337.387704 0.085602523 3814
2
46 3646.387449 -164.087449 -0.371474391 3814.6
-
47 3955.387194 364.487193 -0.825155484 3815.3
9
-
48 4264.386939 563.386938 -1.275440756 3815.9
8
-
49 4573.386684 760.786683 -1.722330207 3816.6
7
Sum =
3951.605
Question 4
lnP*=A-BT-C
You must perform non-linear regression to determine the best values of A, B and C.
Rearrange,
Tpredict=BA-lnP*+C
Solution:
P T T_pred(˚ C) e=T- e^2 T - T_avg (T - T_avg)^2
(atm) (˚C) T_pred
R2=1-SSESST
Where,
SSE=i=1n(yi-yipred)2
= 21.4103233639
= 142220.9843478260
Hence,
R2=1-21.4103233639142220.9843478260
R2= 0.999849457
➢ A = 11.8161341
➢ B = 3886.240338
➢ C = -228.0943652