Part A. System of Linear Equations: Computer Lab # 3
Part A. System of Linear Equations: Computer Lab # 3
Part A. System of Linear Equations: Computer Lab # 3
Name: Click here to enter text. Student ID: Click here to enter text.
Date: Click here to enter text. Time: Click here to enter text.
Computer lab # 3
Instructions:
U r3 U 0 C2 U r3 U 0 U r 4 k3V3 C3 U r 4 C4 0
U 0 U r 4 C3 U 0 U r 4 k4V4 C4 0
The four equations can be written matrix form. The cells from M12 to P16 represent the 4x4
coefficients, cells Q12 to Q16 contain C1 to C4. The values of U3R and U4R are in cell J18 and J19.
Question A2. You need to save your Excel in the macro-enabled format. Go to sheet A2. Write
a VBA code to solve the system using Gaussian-Seidel iterative method (see the hints for VBA
code). What are the solutions?
Question A3. If U3R = 80 L/hr, how much should be recycled from 4 th reactor (i.e. U4R) to achieve
the final concentration C4A = 0.5 mol/L?
Hints
You can use the following structure for the Gauss-Seidel method. The inputs are A – matrix of
coefficients (n rows by n columns), B – an array (n element), Cguess – an array (n element), tol –
err. The output is Cin – an array of n elements.
cnew(row) = (b(row) - sum + Cin(row) * a(row, row)) / a(row, row) 'calculate Cnew
err(row) = Abs(cnew(row) - Cin(row)) 'there will be n errors, the code stops when ALL errors <
tol, or sum of all errors < tol....
………………….’ updating values, cin(1,2,3,4) will be the input at start of next loop
…………………………………………..’calculate MaxErr for each iteration
Next row
Debug.Print k, Cin(1), Cin(2), Cin(3), Cin(4), MaxErr ‘showing these values in the Intermediate
Window
CHEN2004 2020
Notes:
For G-S methodology (see picture below), you can either use
For col=1 to n
Sum=Sum + a(row,col)*cin(col)
Next col
Cnew(row)=(b(row)-sum+a(row,row)*cin(row))/ a(row,row)
OR
For col=1 to n
If col<>row then
Sum=Sum + a(row,col)*cin(col)
End if
Next col
Cnew(row)=(b(row)-Sum)/a(row,row)
The concentration of fatty acids (A) in a biodiesel reactor is given as a function of time by a function
of A is given by:
dA
=40−3 A
dt
At t=0, the fatty acid concentration is 50 g/L.
Solve numerically for fatty acid concentration after 1 minute:
1. Euler method with a step size of 0.5
5. Compare the numerical solutions in terms of the number of calculations, accuracy at t=1 and
overall accuracy.