You are on page 1of 3

MECH 2150 Mechanical Engineering Modelling and Numerical Methods Fall 2021

Computer Lab Project #3 – Linear Systems


Due: Friday, October 29th 2021 at 11:30pm
1. Learning Objectives
The learning objectives of this lab are as follows:
 Understand how to transform a differential equation into an algebraic equation using finite
difference approximations.
 Learn how loops may be used in MATLAB to set up a coefficient matrix.
 Practice writing MATLAB function files that implement various numerical methods for solving
a linear system of equations.
 Understand how to use built-in MATLAB plotting functions.
 Analyze the effect of increasing the number of nodes in a domain on the accuracy of the
numerical results.
 Analyze how the Gauss Seidel method converges for various relaxation factors.
 Compare the performance of various numerical methods in solving the proposed problem.

2. Problem Description
Fluid flow through the parallel channel shown schematically in Figure 1 is defined by the following 2 nd
order ordinary differential equation:

 y  d 2 u  du
0  1.34   2  0 G [1]
 b  dy b dy

Where 𝑢 is the velocity of the fluid in [m/s], 𝑦 is the distance measured from the centerline of the
channel in [m] (see figure), 𝜇 = 0.4 [kg/m∙s], 𝐺 =-20 [Pa/m] is the pressure gradient and 𝑏 = 0.5 [m]
is the half-width of the channel. The bottom of the channel is stationary and the top wall of the
channel is moving at a constant velocity of 𝑢 = 3 [m/s].

Using the finite difference method with a centered difference approximation of 𝑂(ℎ ) for the
derivative terms, write a MATLAB code that sets up the matrix of equations and uses the Tri-Diagonal
Matrix Algorithm (Tdma) and the Gauss Seidel method with relaxation to solve for the velocity profile
𝑢(𝑦). Ensure that your results are grid independent (i.e. increasing the number of nodes does not
have a significant effect on the velocity distribution. Further details on how to ensure grid
independent results can be found in the following section.

Figure 1 – Fluid Flow through Parallel Channel

Page 1 of 3
MECH 2150 Mechanical Engineering Modelling and Numerical Methods Fall 2021

3. Method
Function Files:

Two function files must be written for each of the numerical methods listed in the Problem Description
above (Tdma.m, GaussSeidel.m).

Tdma.m: Input variables for this function are the coefficient matrix and the right-hand column vector and
the output variable is the solution vector (velocity for this problem). You may use (but are not required
to) the template provided on UM Learn for this function.

GaussSeidel Function: Input variables for this function are the coefficient matrix, the right-hand column
vector, the relaxation factor, the error tolerance and the maximum number of iterations. Output variables
are the solution vector and the number of iterations required for convergence. You may use the Gauss
Seidel function provided on UM Learn for guidance in creating your function.

Script File:

Two script files (Lab3a.m and Lab3b.m) must be created. Each script file should do the following:

1. Create variables for all the parameters in Eqn. 1 and the boundary conditions (𝐺, 𝑏, 𝜇 , 𝑢
and 𝑢 ).
2. Specify the number of nodes as 5 for the first iteration. The number of nodes will be a variable
that increases with each iteration.
3. Compute the spacing between the nodes 𝑑𝑦, the 𝑦 location of each node and set up the
coefficient matrix 𝐴 and the right-hand column vector 𝐵. These must be done using a loop since
changing the number of nodes will change the size of the matrix and the values of the coefficients
in the matrix.
4. Call the Tdma (Lab3a.m) or the Gauss Seidel (Lab3b.m) function to solve for the velocity profile.
5. Plot the velocity profile results on a 𝑢 vs. 𝑦 graph.
6. Determine the maximum velocity across the channel and the error between the maximum
velocity with the current number of nodes and the maximum velocity with 5 fewer nodes. If the
error is greater than 0.001%, increase the number of nodes by 5 and repeat the calculations
starting at step 3.

* Note on clear and clc: Remember to include the ‘clear’ and ‘clc’ commands as the first two commands
in your script file.

* Note on plotting: Use the “hold on” command to plot a new set of results (using more nodes) on top
of an old set of results.

4. Results and Discussion


Include the following results/discussions in your report:

 A table containing the following information for both Tdma and Gauss Seidel methods:
o Number of nodes required for convergence
o The maximum velocity from the converged results
o Relaxation factor (only relevant for Gauss Seidel method)

Page 2 of 3
MECH 2150 Mechanical Engineering Modelling and Numerical Methods Fall 2021

o Number of iterations required for the Gauss Seidel method to converge


o Approximate error after convergence is reached for Gauss Seidel method
o Time it took for each method to converge
 Plot of 𝑢 vs. 𝑦 results from using the Tdma. Include results for all the different mesh sizes
(numbers of nodes) together on one plot. Include a title and axis labels.
 Plot of 𝑢 vs. 𝑦 results from using the Gauss Seidel method. Include results for all the different
mesh sizes (numbers of nodes) together on one plot. Include a title and axis labels.
 Discussion of how the two solution methods performed in terms of:
o Ease of programming
o Solution time (use tic toc commands in code for this and note that the difference in
time becomes more obvious when you use a large number of nodes)
o Accuracy
 Discussion of how the number of nodes affected the accuracy of the results. How did the
plots change as more nodes were added?
 Discussion of the selected relaxation factor when using the Gauss Seidel method. Does using
over or under relaxation help the solution converge faster?

5. Submission Requirements
You may work with a partner for the lab but regardless of if you are working with a partner or not,
each student must submit the report as a pdf document and the four MATLAB m-files (Lab3a.m,
Lab3b.m, Tdma.m and GaussSeidel.m) electronically on UM Learn. If you are working with a partner,
all these files (m-files and report) should be identical to your partner’s files. Please combine all the
files mentioned above into a folder and compress the folder into a zip file. Then upload the zip file to
the Assignment folder. Each student will then only have one zip file they are submitting. Please name
the zip file as Lab3_LastName_StudentNumber (ex. Lab3_Guyot_1234567).

Page 3 of 3

You might also like