ENG1060 Assignment Page 1 of 8
ENG1060 ASSIGNMENT – S1 2017
Due: 11:00PM (Sharp), Friday 19th
May 2017 (week 11)
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.
Collaborating with others to discuss algorithms and details of MATLAB syntax and structures is
acceptable (indeed encouraged), however you MUST write your own MATLAB code. All
assignments will be checked using plagiarism-detecting software and similarities in submitted
code will result in a human making a decision on whether the similarity constitutes plagiarism.
INSTRUCTIONS
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 and Q2 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:
1) 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
Follow “ENG1060 Assignment ZIP file instructions.pdf” to prepare your zip file for submission.
Your assignment will be marked in your usual computer lab session during Week 12. YOU MUST BE
IN ATTENDANCE TO HAVE IT MARKED. IF YOU DO NOT ATTEND YOUR MARK WILL BE ZERO. 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 in the computer labs (especially if you have used MATLAB on a Mac
OS or Linux system). ENG1060 Assignment Page 2 of 8
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) You can ask questions in the Discussion Board on Moodle
2) Hints and additional instructions are provided as comments in the assignment template M-Files
3) Hints may also be provided during lectures
4) 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.
5) I 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.
6) 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.)
Question 1 starts on the next page.
ENG1060 Assignment Page 3 of 8
QUESTION 1 [10 MARKS]
Background
Oceans experience differential heating from the equator to the poles. This type of heating can be
considered as horizontal convection whereby a single boundary has varying temperature. Horizontal
convection causes the flow to shift from cold to the hot regions, generating a recirculation.
Researchers wish to study the dynamics of the ocean by understanding the fundamentals of
horizontal convection.
Since it is not possible to conduct experiments at the scale of oceans, researchers instead replicate
horizontal convection behaviours at smaller scales, often in a rectangular enclosure. An example
apparatus is illustrated in figure 1.
Figure 1: Example apparatus reproducing horizontal convection where the bottom boundary has
cold and hot forcing. The contours are of temperature where blue and red represent low and high
temperature values, respectively.
Several non-dimensional parameters are introduced to govern and quantify the experiments. These
parameters are listed below:
• Aspect ratio, A, which provides the ratio between the height to length of the enclosure
• Rayleigh number, Ra, which provides the ratio between buoyancy and viscous forces
• Nusselt number, Nu, which provides the ratio between convective and conductive heat
transfer
Thus, a large Rayleigh number represents a large temperature difference that is imposed along the
bottom boundary of the apparatus and a large measured Nusselt number represents strong
convection induced by the flow.
A researcher often conducts several experiments at various Rayleigh numbers and measures the
corresponding Nusselt numbers in the flow. The number of experiments conducted is not fixed and
varies depending on what the researcher is after. For example, the researcher may run experiments
for 10 different Rayleigh numbers on Tuesday but then run it for 30 different Rayleigh numbers on
Wednesday. However, the results are always stored into a file named "experimental_data.csv". The
structure of the csv file is as follows:
• 1st
column: A
• 2nd
column: Ra
• 3rd
column: Nu ENG1060 Assignment Page 4 of 8
You are asked to post-process this data by completing the following tasks. Note that your coding
should adopt good programming practices such that they work with any number of Rayleigh
numbers and aspect ratios provided in the "experimental_data.csv" file, unless otherwise specified.
Q1a
In the Q1a.m file, import the data from "experimental_data.csv". Use a for loop to restructure the
imported numerical data into a three-dimensional matrix, where each two-dimensional matrix
plane contains the Ra and Nu data for a single A value. An illustration is provided in figure 2. Note
that each two-dimensional plane has the same dimensions to be consistent, though the Ra values in
each plane may differ.
Figure 2: (left) An illustration of a three-dimensional matrix where each two-dimensional matrix
contains the Ra and Nu data for a specific A. (right) An example code of storing matrices into a three-
dimensional matrix.
Hint: The unique() function returns sorted values in an array but with no repetitions.
Q1b
In the Q1b.m file, plot Nu against Ra on linear axes for each aspect ratio in the text file, starting
with the smallest aspect ratio. All the curves should be on a single figure. The legend should be
placed in the north-west location and can be manually defined.
In a separate figure, plot Nu against Ra on logarithmic axes for each aspect ratio in the text file,
starting with the smallest aspect ratio. All the curves should be on a single figure. The legend for this
figure should also be placed in the north-west location and can be manually defined.
*You should have two figure windows by the end of this task.
clear all; close all; clc;
%A 3x3 matrix
A = [1 2 3; 4 5 6; 7 8 9];
%Another 3x3 matrix
B = [11 22 33; 44 55 66; 77 88 99];
%Creating matrix C which is 3D
%Storing A into 1st plane of matrix C
C(:,:,1)=A;
%Storing B into 2nd plane of matrix C
C(:,:,2)=B;
3D matrix ENG1060 Assignment Page 5 of 8
Q1c
Upon observation of the Nu-Ra curves on the logarithmic axes, you notice that the curves are
generally described by three trends belong to three regimes:
• Conduction regime: Low Ra and constant Nu
• Convection regime: Intermediate Ra and rapidly increasing Nu
• Unsteady regime: High Ra and moderately increasing Nu
The vague descriptions for these regimes above do not allow researchers to precisely determine the
Ra value at which the flow transitions from a conduction regime to a convection regime. This
transition point is known as the critical Ra (written as Rac) and the corresponding Nu is (Nuc).
Therefore, you specify a quantitative definition for (Rac, Nuc) as follows:
1. For each value of A separately, starting at the lowest value of Ra and moving to higher values,
determine the percentage difference in Nu values between the current Ra value and the first
Ra value
2. If the percentage difference is greater than a user specified tolerance (e.g. 5%), then the
transition point (Rac, Nuc) is determined to be the current Ra and Nu.
In the Q1c.m file, complete the function file such that it determines the (Rac, Nuc) values for a set
of Ra and Nu data. The function header provided is:
function [Rac, Nuc] = Q1c(Ra,Nu,percent_tol)
Hint: The percentage difference is defined as
!"!"##$%& !"!!"!"#$%& !"
!"!"##$%& !"
×100%
Q1d
In the Q1d.m file, use the Q1c function (written in part Q1c) to determine the (Rac, Nuc) values for
each aspect ratio. Use a percentage tolerance of 5% for the percentage difference. Print these
critical values to file named "ARaNu.txt" in a structure like the following using the following
properties (values shown are placeholders):
A Ra_c Nu_c
0.000000 0.00e+00 0.0000
0.000000 0.00e+00 0.0000
0.000000 0.00e+00 0.0000
0.000000 0.00e+00 0.0000
0.000000 0.00e+00 0.0000
0.000000 0.00e+00 0.0000
• A header with strings A, Ra_c, and Nu_c, all with a width of 10
• Width of 10 for the A values using fixed-point notation with the default number of decimal
places
• Width of 10 for the Rac values using exponential notation with 2 decimal places
• Width of 10 for the Nuc values using fixed-point notation with 4 decimal places
*You should still have two figure windows by the end of this task.
ENG1060 Assignment Page 6 of 8
Q1e
In the Q1e.m file, plot the (Rac, Nuc) points on the Nu-Ra curves plotted on logarithmic axes
produced in part Q1b. The critical points should be plotted as red asterisks. Thus, the figure should
illustrate where the flow transitions from the conductive to convective regime.
*You should still have two figure windows by the end of this task.
Q1f
You notice that the (Rac, Nuc) points appear to form a straight line on the logarithmic axes.
In the Q1f.m file, plot the (Rac, Nuc) points in a new figure as red asterisks on logarithmic axes.
A straight line in log-log coordinates corresponds to one of the non-linear regression models
discussed in ENG1060. In this question, you will fit this non-linear model to the set of data points
plotted with red asterisks. To do this, linearise the (Rac, Nuc) points and determine the non-linear
equation which fits through this data (NOTE: You can use polyfit if you wish). Plot this non-linear fit
on the same figure as a blue line with Rac values given by 100 logarithmically equi-spaced values
between 106
to 1012
. The title of the figure should be the fitted non-linear equation. E.g. Nu_c =
00.0000*Ra_c^0.0000
*You should have three figure windows by the end of this task.
Q1g
In the Q1g.m file, plot Rac as a function of A in a new figure as black asterisks on logarithmic axes.
Also, linearise the (Ac, Rac) points and determine the non-linear equation which fits through this
data. Plot this non-linear fit on the same figure as a blue line with A being 100 logarithmically equi-
spaced values between 10-4
to 101
. The title of the figure should be the fitted non-linear equation.
E.g. Ra_c = 00.0000*A^0.0000
Determine the Rac value required for the flow to transition from the conduction regime to the
convection regime for A=10-4
, as predicted by the non-linear fit. Use fprintf to print a statement
containing the Rac value required for A=10-4
like the following (values shown are placeholders):
An aspect ratio of 1.00e-04 requires Ra=0.00e+00 to
transition from conductive regime to convective regime
Assuming an ocean has an aspect ratio of A=10-4
with Ra=O(1030
), do you expect the ocean to be in a
conductive regime or a convective regime? Use fprintf to print your answer and to explain why.
*You should have four figure windows by the end of this task.
Q1h
In the Q1h.m file, use the bisection method (can be a separate function file or embedded into the m-
file) to determine the Rac value that achieves Nuc=10-1
. Find the root to a precision of 10-6
using ENG1060 Assignment Page 7 of 8
lower and upper bracket values of xl=106
and xu=1010
, respectively. Use fprintf to print your answer
of Rac to 3 decimal places using exponential notation.
Q1i
You wish to quantify the departure of the Nu profiles at various A values from the Nu profile at the
smallest A profile (i.e. A=0.015). To do so, you use the following measure:
𝐨𝐩 =
𝐵!!!
!"!!"!"
!"!!"! d𝐵 − 𝐵!!!.!"#d𝐵
!"!!"!"
!"!!"!
𝐵!!!.!"#
!"!!"!"
!"!!"! d𝐵
Here, NuA=X represents the Nusselt number profile for A=X where X can be 0.02, 0.03, 0.04, 0.06 and
0.08. Naturally, the departure value D for A=0.015 will be zero. Note that the integral limits span the
lowest Ra to the highest Ra that the file contains (i.e. all data). D values greater than 1 is of large
departure while D values smaller than 1 is of small departure.
In the Q1i.m file, use the composite trapezoidal rule (can be a separate function file or embedded
into the m-file) to integrate the appropriate values to calculate the departure value D for A=0.02,
0.03, 0.04, 0.06 and 0.08. It is important to note that the data is not regularly spaced and therefore
you will need to work with the data points provided to calculate the integral, as opposed to using
values from a fitted function. Use fprintf to print your answer of D for each A (not including
A=0.015) and state whether it’s a small or large departure. Your output should look like the
following (values and text shown are placeholders):
D=0.0000 for A=0.0200 and is considered small departure
D=0.0000 for A=0.0300 and is considered large departure
D=0.0000 for A=0.0400 and is considered small departure
D=0.0000 for A=0.0600 and is considered large departure
D=0.0000 for A=0.0800 and is considered small departure
Q1j
Whilst researching horizontal convection, a colleague comes across an image with two encoded texts
which were supposedly sourced from the lost city of Atlantis. These texts are comprised of random
numbers and letters. These texts are provided below.
Figure 3: The two encoded texts from the lost city of Atlantis.
ENG1060 Assignment Page 8 of 8
Upon further research, your colleague comes across what appears to be the key to decode the texts!
It turns out that the numbers in the encoded text represent letters from a to z and from A to Z. The
letters in the encoded text represent the numbers 0 to 9. Your colleague is too lazy to decode the
texts manually and therefore asks you to write MATLAB code to decode these texts using the
decoding keys provided in Q1h.m (see below).
Example interpretations:
• The number 50 in the encoded text represents the letter 'a' when decoded
• The number 24 in the encoded text represents the letter 'e' when decoded
• The letter 'r' in the encoded text represents the number 0 when decoded
• The letter 'q' in the encoded text represents the number 3 when decoded
In the Q1j.m file, write MATLAB code to decode the two encoded texts. Use fprintf to print the
decoded string. The encoded text has already been provided to you in the Q1h.m file as cells. In the
encoded texts, the spaces are treated as spaces and dashes are ignored.
Note: The encoded texts are contained in cells rather than matrices. Addressing elements of a cell is
the same as addressing elements of a matrix, except curly braces {} are used rather than parentheses
(). The cell function creates an empty cell with the specified size.
Hint: You may want to use the ischar() function to determine if an element of the cell is a string or
number.
Poor Programming Practices [-2 Marks]
(Includes, but is not limited to, poor coding style or insufficient comments or
unlabeled figures, etc.)
(END OF ASSIGNMENT)
%% pre-defined variables
letters = ['a':'z','A':'Z'];
numbers = 0:9;
letter_key = [50,47,34,42,24,30,22,17,41,23,25,20,35,38,48,43,18,2,27,...
44,11,8,36,45,29,26,33,1,19,46,3,4,10,14,16,37,39,15,7,40,52,6,49,...
9,5,21,13,31,28,51,12,32];
number_key = 'rejqucykml';