Assignment title: Information
MCD4140 Assignment Page 1 of 6
MCD 4140: Computing for Engineers
Assignment
Trimester 1, 2016
Status: Individual
Hurdle: There is no hurdle on assignment
Weighting: 10%
Word limit: No limit
Due date: By 12.00pm on Monday 09/05/2016 via Moodle.
INSTRUCTIONS
This assignment should be completed INDIVIDUALLY. Plagiarism will result in a mark of
zero. Plagiarism includes letting others copy your work and using code without citing the
source. If a part of your code is written in collaboration with classmates, say so in your
comments and clearly state the contributions of each person.
Download template.zip from Moodle and update the M-Files named q1a.m, q2.m, etc. with your
assignment code. DO NOT rename the M-Files in the template or modify run_all.m. Check your
solutions to Q1 and Q2 by running run_all.m. The teacher will only run the run_all.m file when
marking.
SUBMITTING YOUR ASSIGNMENT
Submit your assignment online using Moodle. You must include the following attachments:
A ZIP (NOT .rar or any other format) file named after your student ID containing the following:
a. An assignment coversheet with your name and ID
b. Solution M-Files for assignment tasks named: q1.m, q2a.m, etc.
c. Any additional function files required by your M-Files
d. All data files needed to run the code, including the input data provided to you
We will extract (unzip) your ZIP file and mark you based on the output of run_all.m. It is your
responsibility to ensure that everything needed to run your solution are included in your ZIP file.
MCD4140 Assignment Page 2 of 6
MARKING SCHEME
This assignment is worth 10% (1 Mark == 1%). Code will be graded using the following criteria:
1) run_all.m produces results automatically (no additional user interaction needed to fix your code)
2) Your code produces correct results (printed values, plots, etc…) and is well written.
ASSIGNMENT HELP
1) Hints and additional instructions are provided as comments in the assignment template M-Files
2) Hints may also be provided during Lectures/Labs
QUESTION 1 [6 MARKS]
Background information
The transport of liquids in pipes is ever present in the real world. Examples include transporting
drinking water from a dam to a town water supply, pumping oil in an undersea pipeline, transporting
milk in a dairy. All of these applications and many others require careful design of the system
including choosing the best pipe diameter and the sizing of the pump to ensure both efficient pumping
at the same time as having an ability to turn the flow rates up or down during times of high and low
demand.
Pipe flow is characterised using two derived parameters. First we define a dimensionless group called
the Reynolds number (Re) that is defined by
Eqn 1
In Eqn 1, ρ is the fluid density, U is the mean fluid velocity in the pipe (given by the volumetric flow
rate Q m3s-1 divided by the pipe cross-sectional area πD2/4), D is internal pipe diameter and µ is the
dynamic viscosity (measured in Pascal seconds).
Second we define the Darcy friction factor that relates the pressure gradient (dP/dx) required to drive
the flow to the speed of the flow. The friction factor f is given by
Eqn 2
You are going to install a pumping system to transport water from a ground water desalination plant to
a small remote community in a 50mm (ID) plastic pipe, but you don't know what pump you need to
use. You search your company's internal reports and come up with lots of data where previous
research has measured the pressure drop in a smooth-walled pipe as a function of the applied pressure
gradient. You have put all this data into a single file called "Pipe_Data.txt". Each line has the result
of one measurement and has the following format
MCD4140 Assignment Page 3 of 6
Line 1 – Column headers
Line 2 – Column units (e.g. mm, seconds, kg, etc.)
Line 3 – Pipe diameter, Mean velocity, Fluid density, Fluid viscosity, Pressure gradient
Line 3 – Pipe diameter, Mean velocity, Fluid density, Fluid viscosity, Pressure gradient
" " " " "
" " " " "
Line N+2 – Pipe diameter, Mean velocity, Fluid density, Fluid viscosity, Pressure gradient
You are not sure how to analyse this data and see in your fluid mechanics text book that the data for
smooth walled pipes can be "collapsed" into a form where the friction factor is related to the Reynolds
number in the following way
Eqn 3
If you can determine appropriate values for "A" and "n" in Eqn 3 from your data, then you will be
able to determine the pressure gradient you need.
Question 1
NOTE: Where your MATLAB code is required to do something (plot, print, etc.) I have
explicitly stated "OUTPUT:"
Q1a. Read in the pipe flow data from "Pipe_Data.txt".
Then you need to calculate the Reynolds number and the friction factor for each of the measured
values in the file. (IMPORTANT NOTE: You MUST ensure that all units in your data are
consistent, i.e. S.I. units – you cannot mix units)
OUTPUT: Create a figure with two sub-plots (one above the other). In the top sub-plot, plot f vs Re
as a linear-linear plot, with each data point as a solid green circle (do NOT join these symbols with a
line). In the lower sub-plot plot the same information in log-log coordinates (using the MATLAB plot
command loglog). Plot each data point as a solid red circle (again, do NOT join these symbols with a
line).
MCD4140 Assignment Page 4 of 6
Q1b. Write a MATLAB function that will undertake a non-linear least squares fit to a set of data
points (xi ,yi). You can use polyfit inside this function or write your own least squares code as you
wish, but you will need to choose which type of non-linear model fit is appropriate. Use this
MATLAB function and fit a curve to ALL of your data in order to estimate the coefficients "A" and
"n" in Eqn 3 and return these two values as the output arguments of the function.
OUTPUT: Write the kind of non-linear regression you are using to the command window.
OUTPUT: Create a figure. Plot your best fit function (using a solid black line with a line width 2)
AND the data points with solid green circles.
OUTPUT: Write the coefficients "A" and "n" that your model predicts, and the coefficient of
determination (r2) of the fit into the top sub-plot.
Q1c. The Colebrook equation is a different correlation that relates the friction factor to the Reynolds
number for turbulent flow (we will define turbulent flow here as being Re > 2,500). It is usually
regarded as more accurate than the power law expression you found in the previous equation. For a
smooth pipe it is written
Eqn 4
This is an implicit equation that cannot be solved analytically for the friction factor, f. However, you
can use a root finding algorithm to find f if you know Re.
Write a function called FrictionFactor that calculates the friction factor using the Colebrook equation
and an input value of Re in the turbulent region. If Re is in the laminar regime (i.e. Re<=2500), the
function should print an error message (i.e., there should be error checking INSIDE the function).
You may use any root finding method you like (including in-built MATLAB functions).
OUTPUT: In script Q1c, put the friction factor calculation inside a while loop that asks for an input
Reynolds number and then prints to the screen the friction factor from your function
"FrictionFactor.m" and also the percentage difference between your power law fit in Q1b and the
value from the Colebrook equation.
You will also need to implement a sensible criteria to stop the while loop so that the run_all.m script
can continue to execute and do Question 2.
NOTE: The values you calculated in Q1a and Q1b will needed to be used in Q1b and Q1c. You
can pass these as output/input parameters or use the "global" command.
MCD4140 Assignment Page 5 of 6
QUESTION 2 [3 MARKS]
Assuming that you are part of a project team in a Telecom company, your project is focusing on the
following wireless communications between a base station and a mobile handset.
Assuming the Base station is transmitting a set of binary bits x = [0 0 0 0 1] to the mobile handset,
what you expect is to receive the same signal x at the mobile handset. However, due to surrounding
noise, the recovered message in mobile handset is y = [1 0 1 0 0] ≠ x. Comparing transmitted signal x
and received signal y, they are different in 3 digits (marked in red), or we can say that there are 3 bits
in error in y. Hence the error rate in this wireless communication is 0.6 (i.e., 5 bits are transmitted
and 3 bits are in error).
Q2a) Now we transmit a set of 100 bits from the base station to mobile handset, and the transmitted
data is saved to the file transmitted_bits.txt. The recovered signal in the mobile handset is stored in
the file received_bits.txt. Now, write a MATLAB code to load both transmitted_bits.txt and
received_bits.txt data into MATLAB. Then compute the error rate in this wireless communication.
OUTPUT: Using the command 'fprintf' to print out the error rate as a floating point number with
two decimals and start a new line after this print out.
Q2b) Now we consider the scenario that the Base station communicates with many mobile users, say
10 users.
)
) )
...
) ) )
) ) )
MCD4140 Assignment Page 6 of 6
Then we measure the received signal-to-noise ratio (SINR) at each mobile receiver. Normally the
SINR data is measured in dB (decibel). If the SINR is greater than or equal to a given Threshold T,
we say this mobile is in coverage and can work properly. Otherwise, we say that this mobile is in
outage and cannot work properly.
We have measured the received SINRs at those 10 mobile terminals, and we saved the SINR values in
the text file SINR.txt. Assuming that our threshold T is 1 dB, write a MATLAB code to load
SINR.txt.
OUTPUT: Create a figure where the x-axis is the mobile number (i.e. 1, 2, etc.) and the y-axis is the
mobile SINRs. The plot will use red circles as data markers with no line in between. Add the title
'Received SINRs' to the figure. Label the x-axis as 'User number' and the y-axis as 'SINR'.
Then find out how many users are in Outage and how many users are in Coverage.
OUTPUT: Print out both results using 'fprintf' and '%d'.
NOTE: After completing parts (a) and (b), you should end up with only ONE M-file for
question 2.
Good Programming Practices (Coding style and Comments) [1 Mark]
(END OF ASSIGNMENT)