Microsoft Word - MCD4140_Assignment_T1_2020.docx
MCD 4140: Computing for Engineers
Assignment
Trimester 1, 2020
Status: Individual
Weighting: 10%
Due by: 11:55pm on Monday Week 10 (May 4, 2020)
Late penalty: Deduct 10% per day
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.
NOTE: Your MATLAB code will be checked for plagiarism – DON’T RISK LOSING ALL 10 MARKS BY
COPYING SOMEONE ELSE’S CODE (OR BY ALLOWING SOMEONE ELSE TO COPY YOURS).
Download the assignment template files from Moodle and update the m‐files named Q1a.m, Q1b.m,
etc… with your assignment code. DO NOT rename the m‐files in the template or modify run_all.m.
Check your solutions to all the tasks by running run_all.m and ensuring all questions are answered
as required. Do not use close all, clear all, clc in any individual mfiles.
SUBMITTING YOUR ASSIGNMENT
Submit your assignment online using Moodle. Your ZIP file (not .rar or any other format) must
include the following attachments:
a. Solution m‐files for assignment tasks (e.g. run_all, Q1a.m, Q1b.m, etc.)
. Any additional function files required by your m‐files (e.g. heun.m, falseposition.m, etc.)
c. All data files needed to run the code including the input data provided to you (e.g.
data1.txt, data2.csv, etc.)
d. A completed cover sheet
Your assignment will be marked in your usual computer lab session during Week 11. YOU MUST
ATTEND AND FACE A SHORT INTERVIEW TO HAVE IT MARKED. IF YOU DO NOT ATTEND THE
INTERVIEW, YOUR ASSIGNMENT MARK WILL BE ZERO. YOUR ZIP FILE WILL BE DOWNLOADED FROM
MOODLE DURING WEEK 10 AND ONLY THESE FILES WILL BE MARKED. We will extract (unzip) your
ZIP file and mark you based on the output of run_all.m on a Windows‐based system. It is your
esponsibility to ensure that everything needed to run your solution is included in your ZIP file. It is
also your responsibility to ensure that everything runs seamlessly on a Windows‐based system
(especially if you have used MATLAB on a Mac OS or Linux system). Windows OS computers are
available in the computer labs on campus for testing. The assignment will not be downloaded to your
individual laptops for marking.
MARKING SCHEME
This assignment is worth 10% (10 marks = 1%) of the unit mark. Your assignment will be graded
using the following criteria:
1) run_all.m produces results automatically (additional user interaction only if asked explicitly)
2) Your code produces co
ect results (printed values, plots, etc…) and is well written.
3) Coding interview performance
CODING INTERVIEW RUBRIC
As part of the marking process, your demonstrator will spend a few minutes interviewing you to gauge
your understanding of the assignment code. The purpose of this is to ensure that you have contributed
to the assignment and understand the code.
You will be assigned a score based on your interview and your code mark will be penalized if you are
unable to explain your submission.
Category Description Penalty
No understanding
(or did not attend
the interview)
The student has not prepared, cannot answer even the most basic
questions and likely has not even seen the code before. 100%
Trivial
understanding
The student may have seen the code before and can answer
something partially relevant or co
ect to a question but they
clearly can’t engage in a serious discussion of the code
30%
Selective
understanding
The student gives answers that are partially co
ect or can answer
questions about one area co
ectly but another not at all. The
student has not prepared sufficiently
20%
Good understanding
The student is reasonably well prepared and can consistently
provide answers that are mostly co
ect, possibly with some
prompting. The student may lack confidence or speed in answering.
10%
Complete
understanding
The student has clearly prepared and understands the code. They
can answer questions co
ectly and concisely with little to no
prompting.
0%
ASSIGNMENT HELP
1) You may use the function files that you have written in the labs.
2) You may ask questions in the Discussion Forum on Moodle.
3) The m‐file templates contain pre‐written comments and sections only as a guide. You do not need
to follow its structure. You may delete the comments.
4) Hints may also be provided during workshops.
5) Bold text has been used to emphasize important aspects of each task. This does not mean that
you should ignore all other text.
6) The questions have been split into sub‐questions. It is important to understand how each sub‐
question contributes to the whole, but each sub‐question is effectively a stand‐alone task that
does part of the problem. Each can be tackled individually.
7) It is recommended that you
eak down each sub‐question into smaller parts too and figure out
what needs to be done step‐by‐step. Then you can begin to put things together again to complete
the whole.
8) Solve the question, of part thereof, by hand before attempting to code the solution.
QUESTION 1 [30 MARKS]
A four‐bar linkage system is shown in Figure 1. The first link, a, is an input link (crank) of length 1. The
second link, b, is a coupler link of length 2. The third link, c, is an output link of length 4. The fourth
link, d, is the fixed link (ground) of length 5. All lengths are provided in metres.
Figure 1. The four‐bar linkage system.
The angular position of the output link (θ4) of a four‐bar linkage co
esponding to the angular position
of the input link (θ2) can be computed using Freudenstein’s equation:
d
a cos θ
d
c cos θ
a b c d
2ac cos θ θ
The following parameters can be used for root finding:
xl = 120ᵒ, xu = 165ᵒ, xi = 120ᵒ, xi‐1 = 110ᵒ, δ = 0.01 and a precision of 0.0001.
Write MATLAB code to perform the following tasks in the q1.m file:
Q1a.
First, write an m‐file to find the value of θ4 for θ2 = 30ᵒ using any open root finding method of your
choice. Print your answer using fprintf. (Hint: The exact solution is 144.834722187769ᵒ).
Q1b.
Next, modify the m‐file from Q1a to find the value of for θ4 for all integer inputs of θ2 = 0ᵒ to 360ᵒ
using any root finding method of your choice. Plot a graph to show the relationship between the input
angles and the output angles.
Q1c.
Explain your choice of root finding method used in Q1b based on your experiments and observations
and write a
ief explanation to the command window.
Q1d.
Finally, modify the m‐file from Q1b so that it writes the data (input angles and output angles, with 15
decimal places) into a text file named fou
ar.txt. Input angles are θ2 = 0ᵒ to 360ᵒ and the output
angles are obtained from the root finding method of your choice.
QUESTION 2 [40 MARKS]
Flows around cylinders of various cross‐sections continue to engender a significant amount of
engineering research interest due to its ubiquitous practicality in society. Examples include
idge
spans and pylons, high‐rise buildings, pipelines, heat exchangers and oil platforms. When fluid (such
as air or water) flows around such bodies, a wake develops which may become unstable and lead to a
development of vortex streets. An example of the vortex street formed by clouds flowing past an
island is illustrated in Figure 2.
Figure 2. Kármán vortex street caused by wind flowing around the Juan Fernández Islands off the
Chilean coast.
The vortices that develop are capable of containing large amounts of energy which can cause damage
to neighbouring structures on impact. Therefore engineers and scientists study the wake dynamics
ehind these bodies with the aim of suppressing the vortex shedding. There are some cases where
vortex shedding is encouraged as to dissipate heat from a heated wall for example. One such
parameter that may be used to investigate the strength of the wake is by measuring the amplitude of
its velocity fluctuations.
An engineer has performed experiments in a water channel involving flow past a triangular prism.
Contours of axial vorticity are shown in figure 3 for visualization purposes. The magnitude of the lift
generated on the triangular cylinder over time is recorded into amplitude_data.xlsx. The amplitude of
the lift provides important information on the strength of the wake and the vortices that could be
shed off of it. The amplitude_data.xlsx file contains:
1. The time, t
2. The amplitude, A
Figure 3. Axial vorticity contours of flow past a triangle oriented at 0ᵒ.
The engineer has asked you to perform the following tasks.
Q2a.
In the q2a.m file, read in the data from the amplitude_data.xlsx. Be aware that there is header
information. Create a figure with two sub‐plots in a horizontal a
angement. In the left sub‐plot, plot
A against t as a black continuous line. In the right sub‐plot, plot loge(A) against t as a blue continuous
line.
Q2b.
In reviewing the plots created in Q2a, you notice spikes with A≥2 occu
ing at odd times between t=0
and t=900. You question the engineer whether or not these spikes may be artificial. The engineer’s
esponse is that he/she had accidentally bumped into the water channel several times throughout the
experiment.
In the q2b.m file, you are required to remove all of the amplitude data co
esponding to A ≥ 2 as they
are e
oneous. Create another figure containing two sub‐plots in a horizontal a
angement. In the left
sub‐plot, plot the A data against t as a black continuous line with the e
oneous data removed. In the
ight sub‐plot, plot loge(A) against t as a red continuous line.
It should be clear that after a certain time, the recorded amplitude begins to be consistently noisy (as
opposed to sporadically noisy). From the plot, estimate the time at which the amplitude becomes
consistently noisy and print its value using the fprintf command.
In a new figure, plot the natural logarithm of the amplitude for times below which contains the
consistently noisy data.
Q2c.
You have shown the engineer plot you created in Q2b with the consistently noisy data removed. The
engineer believe it’s a better idea to remove all of the data from t=900 onwards. This way, both the
sporadically and consistently noisy data is removed.
In addition, the engineer notices that there are two different trends across the data when reviewing
the plot of loge(A) against t created in Q2b. That is, the trend from 0 ≤ t ≤ 60 differs to that of
60 ≤ t ≤ 900.
In the q2c.m file, you are required to segregate the data such that it only includes data for t=0 to 900
(inclusive). With this data, create several plots in a figure environment with three sub‐plots in a vertical
a
angement. The three plots are described as follows:
1. In the top sub‐plot, plot loge(A) against t for times between t=0 and 60 with a magenta
continuous line.
2. In the middle sub‐plot, plot loge(A) against t for times between t=60 and 900 with a red
continuous line.
3. In the bottom sub‐plot, plot loge(A) against t for times between 0 and 900 using the line
characteristics from points 1 and 2. That is, a magenta continuous line between t=0 and 60
and a red continuous line for t=60 and 900.
All specified limits of time are inclusive. Use a line width of 5 for all of these subplots. Title the plots
such that it describes the range of time the data is plotted for. I.e. “Data for t>=0 and t<=60”.
Q2d.
From the plots of loge(A) against t of amplitude against time created in Q2c, you observe that the data
for
0 ≤ t ≤ 60 can be fitted with a second order polynomial while the data for 60 ≤ t ≤ 900 can be fitted
with a linear relationship.
In the q2d.m file, use polyfit to determine the equations for the second order polynomial and the
linear function. Plot the loge(A) against t for 0 ≤ t ≤ 60 and 60 ≤ t ≤ 900 on two separately figures with
lue circle markers. In addition, plot their respective fitted functions as a red continuous line. The titles
of the plots should include the equation of the fit and the coefficient of determination, r2.
QUESTION 3 [30 MARKS]
Background
A residence time distribution (or RTD) is a probability density function that describes how long fluid
stays in a continuous flow chemical reactor. One way of measuring an RTD is to inject a small pulse of
a chemical tracer (e.g. salt, radioactive material or coloured dye) at the inflow of the rector and then
measure the signal at the outflow of the reactor.
At one extreme is a so‐called “plug‐flow” reactor which has no mixing and in which all of the input
pulse of tracer exits the reactor at the same time. Provided there is no short‐circuiting, this time is
given (in seconds) as
= V/Q
where V is the volume of the reactor (in m3) and Q is the flow rate (in m3s‐1).
At the other extreme, a Continuously sti
ed tank reactor (CSTR) is one in which each element of fluid
that is injected into the reactor is instantly uniformly mixed with everything else inside the reactor.
The RTD for a CSTR is a negative exponential function.
Both of these extremes are idealised concepts and can never be realised in practice. In the real world,
the RTD (usually) rises quickly, and then decays slowly, and in this question we investigate some
different RTD’s.
NOTE: You are allowed to use the fact that time vector in the following question is evenly spaced.
Q3a
You have been asked to determine if several different reactors are operating with similar behaviour,
ut you have not been given any information on their size, or design and have only been given a set
of concentration measurements as a function of time, one for each reactor.
First you must open the rtd data file (‘rtd.dat’) and read it into MATLAB using importdata. The first
column of data is the time of the measurement (in seconds), and the other columns are the
concentration measurements (C(t)) of the tracer at the exit of the reactor for an unknown number
of reactors. Determine how many different reactors have been included in the file and print this
number to the command window.
Plot each of the concentration versus time curves on the same figure using a different coloured line
(in order, use as many as needed of black, red, green, blue, magenta, yellow). Ensure your plot has a
legend using the text headers contained in the file.
Q3b
In order to compare the curves, they must be normalized. The normalized RTD curve (often called
E(t)) is defined as
E(t) C(t)
C(t)dt
0
Write a function called CompTrap that calculates the integral of a function using the Composite
Trapezoidal rule. The input parameters are a vector of (evenly spaced) times over the time range [t1,
t2] and a vector of function values that co
esponds to the time vector (you can assume that spacing
of the data is uniform – you do not need to confirm this).
Normalise each of your concentration curves to give E(t) and in a new figure, plot these for each
eactor using the same colours from part a. (NOTE: Instead of integrating to t = you should
integrate to the last point in the data that you read in). Write the normalising value of C(t)dt
0
for each reactor to the command window, one to a line.
Poor Programming Practices [‐10 Marks]
(Includes, but is not limited to, poor coding style, hardcoding, not using loops
where appropriate, insufficient comments unlabelled figures, etc.)
(END OF ASSIGNMENT)