Numerical Methods Machine Problem 1
Numerical Methods Machine Problem 1
Problem Statement
Determine the volume compression ratio (r 1) if the efficiency of the engine is 0.651 given the ratio of
specific heats of air (k) is 1.4, volume expansion ratio (r 2) is 11.82 and ratio of pressure at states 3 and 2
(p3/p2) is 1.3657. The efficiency of the engine is expressed as,
1 p 3 r1 k
η=1−
( )( ( ) )
r 1k−1 p 2 r2
−1
p3 p r1
p2 ( ){ }
−1+k 3
p2 r2
−1
Use any root-finding method except bracketing method to solve the problem. Tolerance is set at
0.00001 and provide valid and logical initial guesses to solve the problem.
Given the values of some parameters, these were substituted in the efficiency equation to be
manipulated giving a revised equation in terms of the volume compression ratio.
1.4
1 r1
0.651=1−
( r 11.4−1 )( 1.3657(11.82 ) −1)
r1
1.3657−1+1.4 ( 1.3657 ) { 11.82
−1 }
1
1−0.651=
( )
r1 0.4 ( 0.0430220244 r 11.4−1 )
0.3657+0.1617580372r 1−1.91198
0=0.01343153058 r 1+ r 1−0.4−0.53965172
f (r 1)=0.01343153058 r 1+ r 1−0.4−0.53965172
Getting the derivative of the derived equation gives,
f (x n)
x n+1=x n −
f ' (x n)
0.01343153058r 1 +r 1−0.4−0.53965172
r 1 , n+1=r 1 , n−
0.01343153058−0.4 r 1−1.4
Looking at the plotted graph for the derived equation shows two points that gives y=0. Therefore, two
initial guesses that could determine the roots were used, r1=7 and r1=15.
Using VBA, Table 1.1 and Table 1.2 show the iterations done to arrive at the final answer:
There are two possible answers however to obtain a constant volume decrease of pressure from state 5
to state 1 the volume compression ratio needs to be greater than the volume expansion ratio.
Therefore, the answer chosen is 14.92568642.
Problems Encountered
The simplification of the equation is one the most difficult in the problem since one wrong calculation
would lead to a wrong solution. It is also required to plot the equation to determine how many roots to
solve and to determine the logical initial guesses to use to minimize the iterations involved. The
graphing of the equation was done using a graphical calculator from the internet. The link can be seen
under the graph and in the reference section of problem 1.
References
Appendix
Public Function XFunction(ByVal x As Double) As Double
XFunction = 0.01343153058 * x + x ^ (-0.4) - 0.53965172
End Function
Public Function XPrime(ByVal x As Double) As Double
XPrime = 0.01343153058 - 0.4 * x ^ (-1.4)
End Function
Sub Newton()
Dim x1, x2 As Double
Dim tolerance, error As Double
Dim i As Integer
tolerance = Sheet2.Cells(10, 3).Value
x1 = Sheet2.Cells(9, 3).Value
If Sheet1.Cells(10, 3).Value = "" Or Sheet1.Cells(9, 3).Value = "" Then
MsgBox ("Give values for absolute error and initial guess.")
Else
i=0
Do
x2 = x1 - (XFunction(x1) / XPrime(x1))
i=i+1
Sheet2.Cells(7 + i - 1, 9).Value = i
Sheet2.Cells(7 + i - 1, 10).Value = x1
Sheet2.Cells(7 + i - 1, 11).Value = XFunction(x1)
Sheet2.Cells(7 + i - 1, 12).Value = XPrime(x1)
Sheet2.Cells(7 + i - 1, 13).Value = x2
Sheet2.Cells(7 + i - 1, 14).Value = XFunction(x2)
error = Math.Abs((x2 - x1) / x2)
If error > tolerance Then x1 = x2
Sheet2.Cells(7 + i - 1, 15).Value = error
Loop Until error < tolerance
Sheet2.Cells(16, 2).Value = x2
Sheet2.Cells(17, 2).Value = error
End If
End Sub
Problem Statement
Determine the displacement components (x j) given the equilibrium equations shown below:
[ A ] ⃗x =⃗b
Where
0 1 2 3 4 5 6 7 8 9
0 8 0 -4 0 0 0 -2 3.464 0 0
1 0 12 0 0 0 0 3.464 -6 0 0
2 -4 0 12 0 -4 0 -2 -3.464 -2 3.464
3 0 0 0 12 0 0 -3.464 -6 3.464 -6
A 4 0 0 -4 0 8 0 0 0 -2 -3.464
5 0 0 0 0 0 12 0 0 -3.464 -6
6 -2 3.464 -2 -3.464 0 0 12 0 -4 0
7 3.464 -6 -3.464 -6 0 0 0 12 0 0
8 0 0 -2 3.464 -2 -3.464 -4 0 12 0
9 0 0 3.464 -3.464 -3.464 -6 0 0 0 12
0
1000
0
1000
4 l 0
b
E 1000
0
1000
0
1000
*Note: The following values are already substituted to the matrix and b for simplification
(a) Use LU decomposition to find the displacement components (x j). Provide the element matrices
for L and U upon decomposition.
(b) Use SOR method and find the optimum value of ω . Set the TOL=0.00001 and use relative
approximation and L-infinity norm as stopping conditions.
The given matrix, A, was decomposed into two matrices, L and U using Doolittle’s Method. Calculations
and programming were all done using MATHCAD with Trahan (2006) as reference to get the two
matrices. The resulting L and U matrices are shown below.
0 1 2 3 4 5 6 7 8 9
0 1 0 0 0 0 0 0 0 0 0
1 0 1 0 0 0 0 0 0 0 0
2 -0.5 0 1 0 0 0 0 0 0 0
3 0 0 0 1 0 0 0 0 0 0
lower 4 0 0 -0.4 0 1 0 0 0 0 0
5 0 0 0 0 0 1 0 0 0 0
6 -0.25 0.289 -0.3 -0.289 -0.187 0 1 0 0 0
7 0.433 -0.5 -0.173 -0.5 -0.108 0 0.026 1 0 0
8 0 0 -0.2 0.289 -0.437 -0.289 -0.493 0.289 1 0
9 0 0 0.346 -0.289 -0.325 -0.5 -0.042 -0.327 -0.122 1
0 1 2 3 4 5 6 7 8 9
0 8 0 -4 0 0 0 -2 3.464 0 0
1 0 12 0 0 0 0 3.464 -6 0 0
2 0 0 10 0 -4 0 -3 -1.732 -2 3.464
3 0 0 0 12 0 0 -3.464 -6 3.464 -6
upper 4 0 0 0 0 6.4 0 -1.2 -0.693 -2.8 -2.078
5 0 0 0 0 0 12 0 0 -3.464 -6
6 0 0 0 0 0 0 8.375 0.217 -4.125 -1.083
7 0 0 0 0 0 0 0 4.119 1.189 -2.597
8 0 0 0 0 0 0 0 0 6 0
9 0 0 0 0 0 0 0 0 0 4.498
To get the values of xj, forward substitution will be done using [L][Z]=[b] given the equation below:
b1
Z1 =
lower 1,1
i−1
b i−∑ lower i , j Z j
j=0
Zi = , where j≠ i∧i=1. . n
lower i , i
0
0 0
1 -4·10 -3
2 0
3 -4·10 -3
Z 4 0
5 -4·10 -3
6 0
7 -8·10 -3
8 2.309·10 -3
9 -9.491·10 -3
This gave the values for Z:
Then to get X, the values of Z were used during the back-substitution process: [U][X]=[Z]. The following
equations were then used to get X. Calculations started at the nth equation since this is the only
equation that can be solved initially. The subsequent calculations uses the second equation below.
Zn
X n=
upper n ,n
1
Z i− ∑ upper i , j X j
j =i +1
Xi= , where j ≠i∧i=( n−1 ) .. 1
lower i ,i
This gives a set of x shown below:
0.001401266679
0.002026278384 Therefore, the values of displacement components using LU
0.0001297334855 decomposition method are:
0.003189946264
x 1=0.001401266679∈¿ x 2=−0.002026278384∈¿
0.0008823327366
X float 10
0.001277261757
0.000004300276937
x 3=−0.0001297334855∈¿ x 4 =−0.003189946264∈¿
0.003383407336
0.0003849001795 x 5=−0.0008823327366∈¿ x 6=−0.001277261757∈¿
0.002110079069
x 7=−0.000004300276937∈¿ x 8=−0.003383407336∈¿
x 9=0.0003849001795∈¿ x 10=−0.002110079069∈¿
1
1
1
1
1
Xguess
1
1
1
1
(b)Using the SOR method, initial guesses were given since the method is iterative. 1
This algorithm was done to different values of ω to determine the least number of iterations. For SOR,
the range of ω is between 1 and 2. Shown below is the narrowed down range to get the optimum ω
(range from 1.26 to 1.45).
Based on the table above, ω of 1.33 will give the least amount of iterations which is 25; therefore, it is
considered the optimum value.
Shown below is the first three and last three iterations using ω=1.33.
Iteration X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 L∞
no.
1 0.092 -0.049 0.597 1 0.976 0.718 0.669 0.496 0.207 0.676 21.251
2 0.304 0.089 0.495 0.626 0.466 0.292 0.255 0.385 0.129 0.2 2.389
3 0.092 0.128 0.24 0.23 0.164 0.086 0.086 0.168 0.03 0.05 3.369
…
23 1.401e- -2.026e- -1.297e- -3.19e-3 -8.823e- -1.277e- 4.3e-6 -3.383e- 3.849e- -2.11e-3 2.039e-
3 3 4 4 3 3 4 4
24 1.401e- -2.026e- -1.297e- -3.19e-3 -8.823e- -1.277e- 4.3e-6 -3.383e- 3.849e- -2.11e-3 4.747e-
3 3 4 4 3 3 4 5
25 1.401e- -2.026e- -1.297e- -3.19e-3 -8.823e- -1.277e- 4.3e-6 -3.383e- 3.849e- -2.11e-3 5.438e-
3 3 4 4 3 3 4 6
These match with the answers obtained from LU decomposition method and the Isolve function in
Mathcad.
Problems Encountered
The problems encountered for item number 2 is the code of SOR. For the LU decomposition, there is
already a built-in code for the decomposition and solution for linear equations which made it easier to
check if the program done is correct. Additionally, there is an LU decomposition code available in the
internet in Mathcad form. As for the SOR, the only reference that is available in terms of coding in
MATHCAD is Gauss-Seidel. Since it is somewhat similar to that of SOR, this became the basis of the SOR
code.
References
LU decomposition:
http://mathforcollege.com/nm/simulations/mcd/04sle/mcd_sle_sim_ludecomp.pdf
Gauss-Seidel
http://mathforcollege.com/nm/simulations/mcd/04sle/mcd_sle_sim_gaussseidel.pdf
Appendix
XansIter row 0
for w 1.251.26 1.45
Linf 1
iter 0
01
01
01
01
01
Xguess
01
01
1
1
1
while Linf TOL
for i 0 n
sum 0
for j 0 n
sum sum A Xguess if j i
i j j
b sum
i
XgaussN
i A
i i
Xrelax w XgaussN ( 1 w) Xguess
i i i
Xrelax Xguess
i i
error
i Xrelax
i
Xguess Xrelax
i i
Linf max( error )
Answer iter
row 1
iter iter 1
Answer w
row 0
row row 1
Answer
w 1.33
Xnew1 Linf 1
iter 0
while Linf TOL
iteration iter
iter 0
for i 0 n
sum 0
for j 0 n
sum sum A Xguess if j i
i j j
b sum
i
Final_Ans LinfXgaussN
1
i A
i i
iter 0
iteration XgaussN
while Linf iter i 1
TOL i
iter ( 1 w) Xguess
Xrelax w XgaussN
iteration
i iter 0 i i
for i 0 n
iteration Xrelax
iter i 11 i
sum 0
Xrelax Xguess
i i
errorforj 0 n
i Xrelax
sum sum A i Xguess if j i
i j j
Xguess Xrelax
i bi sum
i
XgaussN
Linf max( error
i ) A
i i
iteration Linf
iter 21
Xrelax w XgaussN ( 1 w) Xguess
i i i
iter iter 1
Xrelax Xguess
iteration i i
error
i Xrelax
i
Xguess Xrelax
i i
Linf max( error )
iteration Linf
iter 21
iter iter 1
Xrelax