MCD 4140: Computing for Engineers
Assignment
Trimester 1, 2018
Status: Individual
Hurdle: There is no hurdle on assignment
Weighting: 10%
Word limit: No limit
Due date: By 12.00pm on Monday 30/04/2018 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.
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 template.zip 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 Q1 by running run_all.m and ensuring all questions are answered as required.
SUBMITTING YOUR ASSIGNMENT
Submit your assignment online using Moodle. You must include the following attachments:
A ZIP file (NOT .rar or any other format) named after your student ID containing the following:
a. Solution M-Files for assignment tasks named: run_all, Q1a.m, Q1b.m etc…
b. Any additional function files required by your M-Files (PowerFit.m function etc.)
c. All data files needed to run the code, including the input data provided to you
d. An assignment cover sheet with your name and ID
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 is included in your ZIP file (including data files). It is
also your responsibility to ensure that everything runs seamlessly on the (Windows-based) lab computers
(especially if you have used MATLAB on a Mac OS or Linux system).
MCD4140 Assignment
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 except where asked
explicitly)
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
3) 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.
4) We recommend you break 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.
5) To make it clear what must be provided as part of the solution, I have used bold italics and a statement
that (usually) starts with a verb (e.g. Write a function ..., Print the value..., etc.)
3 of 7
MCD4140 Assignment
QUESTION 1 [3 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 corresponding to the angular position of the
input link (θ2) can be computed using Freudenstein’s equation:
dacosθ4 −dccosθ2 +
a2 −b2 +c2 +d2
2ac = cos(θ2 −θ4)
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ᵒ).
Solution has Graph, The question should ask this.
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. You should monitor the output of all iterations to help you choose a suitable root finding
method.
4 of 7
MCD4140 Assignment
Q1c.
Explain your choice of root finding method used in Q1b based on your experiments and observations and
write a brief explanation to the command window.
Q1d.
Finally, modify the m-file from Q1c so that it writes the data (input angles and output angles, with 15 decimal
places) into a text file named fourbar.txt. Input angles are θ2 = 0ᵒ to 360ᵒ and the output angles are obtained
from the root finding method of your choice.
MCD4140 Assignment
QUESTION 2 [6 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 bridge 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 behind 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
3. The rate of change in the natural logarithm of A, d[loge(A)]/dt
Figure 3. Axial vorticity contours of flow past a triangle oriented at 0ᵒ.
6 of 7
MCD4140 Assignment
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 arrangement. 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 occurring at odd times between t=0 and
t=900. You question the engineer whether or not these spikes may be artificial. The engineer’s response 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 corresponding to A ≥ 2 as they are
erroneous. Create another figure containing two sub-plots in a horizontal arrangement. In the left sub-plot,
plot the A data against t as a black continuous line with the erroneous data removed. In the right 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
arrangement. 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.
7 of 7
MCD4140 Assignment
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 blue 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.
Q2e.
The engineer is now satisfied with how the amplitude data is presented. However, the engineer is also
interested in the rate of change of the amplitude (d[loge(A)]/dt) against the square of the amplitude (A2). Only
data for t ≤ 900 without the noise (removed in Q2a and Q2b) should be considered.
In the q2e.m file, plot d[loge(A)]/dt against A2 using black diamond markers. You notice that there is a strong
linear relationship between the two variables over the range of 0 ≤ A2 ≤ 1 x 10-4. Fit a linear function over this
range, then determine at what value of A the d[loge(A)]/dt variable first falls below 7 x 10-4 by using the
bisection method with a precision of 0.0001. Print the value of A in the command window using the fprintf
command.
Plot the point where d[loge(A)]/dt = 7 x 10-4 with the corresponding A2 value using a red asterisk.
Poor Programming Practices [-2 Marks]
(Includes, but is not limited to, poor coding style. or insufficient comments or
unlabeled figures, etc.)