MCD 4140: Computing for Engineers


MCD 4140: Computing for Engineers
Assignment
Trimester 3, 2018
Status: Individual
Hurdle: There is no hurdle on assignment
Weighting: 10%
Word limit: No limit
Due date: By 12.00pm on Monday 7/01/2019 via Moodle (Week 10).
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 Q1 and Q2 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. Read the “Assignment upload instructions.pdf” to prepare
your ZIP file for submission. 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.)
b. 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 TO
HAVE IT MARKED. IF YOU DO NOT ATTEND, YOUR ASSIGNMENT MARK WILL BE ZERO. YOUR ZIP FILE WILL
BE DOWNLOADED FROM MOODLE AT THE END OF 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 responsibility 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.
MCD4140 Assignment Page 2 of 9
MARKING SCHEME
This assignment is worth 10% (1 Mark = 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 correct results (printed values, plots, etc…) and is well written.
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 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 correct 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 correct or can answer
questions about one area correctly 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 correct, 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 correctly and concisely with little to no prompting. 0%
ASSIGNMENT HELP
1) You can use function files you've written in your labs
2) You can ask questions in the Discussion Board on Moodle
3) Hints and additional instructions are provided as comments in the assignment template m-files
4) Hints may also be provided during lectures
5) 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.
6) It is recommended that 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.
7) The m-file templates contain comments and sections only as a guide. You do not need to follow its
structure.
8) Bold text has been used to emphasize important aspects of each task. This does not mean that you should
ignore all other text.
MCD4140 Assignment Page 3 of 9
QUESTION 1 [3 MARKS]
Background
Accelerometers are small electronic devices that measure acceleration from moving objects. As a trainee
engineer on a racing team, you have been given accelerometer data from a test run at the Watkins Glen
International Racetrack. An image of the racetrack is shown in figure 1.
Figure 1: Satellite view of the Watkins Glen International racetrack.
The data you collected from the accelerometer during a test run is output to a csv file named “race_data.csv”,
which contains:
Time, t (s)
Longitudinal acceleration, ALONG (ms-2)
Latitudinal acceleration, ALAT (ms-2)
G-force lateral acceleration, GLAT (g)
G-force acceleration/deceleration, GAD (g)
Note that 1g = 9.81 ms-2
.
You have been asked to analyse the data and prepare a graphical presentation of the results by performing
the following tasks:
Q1a
In the Q1a.m file, use the importdata() function to import values from the race_data.csv. Create variables for
the time (t), longitudinal acceleration (ALONG), latitudinal acceleration (ALAT), G-force lateral acceleration (GLAT),
and G-force due to total acceleration/deceleration (GAD).
In a 2x2 subplot arrangement, plot the following:
ALONG against t [top left panel]
ALAT against t [top right panel]
GLAT against t [bottom left panel]
GAD against t [bottom right panel]
*You should have one figure window by the end of this task.
MCD4140 Assignment Page 4 of 9
Q1b
In the cumultrap.m file, complete the function file to perform cumulative integration using the trapezoidal
rule given two input vectors. The function should return the cumulative integrated values at the nominated
independent values. You may only use the following built-in functions for your function file: zeros() and
length().
Note: The integral of a set of data returns a scalar result. In contrast, the cumulative integral returns a vector,
whose values represent the integral values from the start of the integration to its current point. Also, note
that integral value of a single point is zero. Read the documentation for cumtrapz() for further details and
use that function to verify your answers.
*You should still have one figure window by the end of this task.
Q1c
In the Q1c.m file, integrate the following equations to obtain the longitudinal and latitudinal velocities V
and displacements D of the race car:
In a new figure with a 1x2 subplot arrangement, plot the following:
Satellite image (track_map.png) of the track using imshow(). [left panel]
Latitude displacements against longitude displacements with the grid on and set the axes to be equal
(option for axis). [right panel]
Also, determine the length of the track. You must use a for loop to complete this task. Use fprintf to print
the length of the track: E.g. Track length: ???m
*You should have two figure windows by the end of this task.
**Use imread() to read the images
Q1d
A strong left turn is identified as when the race car experiences lateral G-forces greater than 0.4g. A strong
right turn is identified as when the car experiences lateral G-forces less than -0.4g.
In the Q1d.m file, determine the left and right-turning corners. In a new figure with a 1x2 arrangement, plot
the following:
G-force lateral acceleration against time [left panel]
Latitude displacements against longitude displacements with the grid on [right panel]
On both panels, mark the following:
Left-turning corners as blue dots
Right-turning corners as red dots
Dots on the left panel are sized 5, and dots on the right panel are sized 15. Remember to include a legend.
*You should have three figure windows by the end of this task.
MCD4140 Assignment Page 5 of 9
Q1e
Acceleration and deceleration zones are identified as follows:
Acceleration zones – where race car experiences G-forces less than -0.1g.
Deceleration zones – where the race car experiences G-forces greater than 0.1g.
In the Q1e.m file, create a new figure with a 1x2 subplot arrangement containing 2 subplots and plot the
following:
G-force due to total acceleration/deceleration against time [left panel]
Latitude displacements against longitude displacements with the grid on [right panel]
On both panels, mark the following:
Accelerating zones as green dots
Decelerating zones as magenta dots
Dots on the left panel are sized 5, and dots on the right panel are sized 15. Remember to include a legend.
*You should have four figure windows by the end of this task.
MCD4140 Assignment Page 6 of 9
QUESTION 2 [3 MARKS]
Background
Monte Carlo methods are a broad class of computational algorithms that rely on repeated random sampling
to obtain numerical results. You have been asked to estimate the value of π using the Monte Carlo method.
A number of randomised points is generated within the box of unit width, as shown in figure 2. Some of the
points lie within the circle, while others lie outside the circle. The value of π is calculated using the following
expression:
where NC represents the number of points inside the unit circle, and NS is the number of dots within the
square. In figure 1, there are 17 points inside the circle and 20 points inside the square (i.e. 3 points outside
the circle). Therefore, ?? ≈
4×17
20
= 3.4. This estimated value of ?? should become more accurate with an
increasing number of points.
Figure 2: Randomised points generated inside a box containing a unit circle.
The procedure to perform the Monte Carlo method is listed below:
1. Generate a randomised point within a square containing a circle of unit radius
2. Determine Nc and Ns, and calculate the estimate of π
3. Repeat steps 1 and 2 for a specified number of points
Complete the following tasks to perform the Monte Carlo procedure described above.
Q2a
In the Q2a.m file, generate a 2x1 subplot arrangement where the top panel contains a circle of unit radius and
a square with a width of 2 units, both centred at (x,y) = (0,0) (see figure 3 for an example). Plot these shapes
as black lines and set the axes to be square (option for axis). Details of the bottom panel are described in Q2b.
MCD4140 Assignment Page 7 of 9
Q2b
In the Q2b.m file, prompt the user for a specified number of points to estimate π using the input() function.
Generate your first randomised point by randomising its x and y-coordinates. The limits for the x and ycoordinates
should be limited to the bounds of the square (i.e. from -1 to 1 in both directions). Plot this
randomised point in the top panel of the figure as a red dot if it lies on or within the circle, or as a blue dot
if it is outside the circle. Use a marker size of 15. After plotting your first randomised point, calculate the
estimate of π and plot the result as a black dot in the bottom panel of the figure (see figure 3). The current
estimate value of π should be stated in the title.
Figure 3: Plot after the 1st randomised point.
Repeat the above instructions until the number of specified points is reached. Update the top and bottom
panels after each new point is created and pause for 0.1 seconds using the pause() function to create an
animated effect. i.e. your top and bottom panels should populate with points over time (see figure 4 for
examples).
Snapshots of the figure after the 3rd and 100
th randomised points are shown in figure 4.
*You should have five figure windows by the end of this task.
Figure 4: (Left) Plot after the 3rd randomised point. (Right) Plot after the 100
th randomised point.
MCD4140 Assignment Page 8 of 9
QUESTION 3 [4 MARKS]
Background
You are part of a team working for the United Nations Environment Programme (UNEP) to investigate the
deforestation process in Borneo. You are provided six images of the forest area in Borneo from 1950-2020,
which comprise of historical and projection data. Forests are represented as green pixels and deforested
areas as yellow pixels.
Q3a
In the Q3a.m file, use the imread() function to read the images. For each year (1950, 1985, 2000, 2005, 2010,
2020), calculate the percentage forested area (PFA) which is defined as:
?????? =
forest area
total land area
× 100% =
green pixels
green and yellow pixels × 100%
Write the year, forested area, total land area and PFA to a file named "BorneoForestData.txt". The file
should look like the following:
Year Forest Area Total Land Area PFA (%)
1950 
1985
...
Hint: Green (forest) in grayscale = 75 to 115 (inclusive)
Light blue (water) in grayscale = 240
Black (text) in grayscale = 0
All other colours in grayscale represent land
*You should still have five figure windows by the end of this task.
Q3b
In the Q3b.m file, plot the PFA against the year as blue circles in a new figure. You believe that the data can
be appropriately represented by either an exponential model or a 2nd order polynomial model. Find the
coefficients for each model based on the form of the equations below:
Exponential model:
nd order polynomial model: 
where α, β, a, b, c are coefficients, and t represents the year.
Plot both fitted models for years 1950 to 2100 (yearly increments) on the newly created figure. Print the
equations of the fitted models to the command window using the exponential specifier for fprintf.
*You should have six figure windows by the end of this task.
MCD4140 Assignment Page 9 of 9
Q3c
In the Q3c.m file, perform the Newton-Raphson method on both models described in Q3b to estimate the
year when Borneo will have no forests left. Perform the root-finding method using precision values of 1e-1,
1e-2, 1e-3 … 1e-10, and present the results in a tabular structure in the command window similar to the
following.
Year Year
Precision Exponential Polynomial
1e-01 
1e-02
1e-03 
Print one sentence that states whether the exponential or polynomial model is more appropriate and
provide justification for your choice.
*You should still have six figure windows by the end of this task.
Q3d
You are asked to further investigate the 2nd order polynomial model considering the effect of neglecting the a
coefficient. Thus, the two ordinary differential equations that may model the Borneo deforestation data are:
Model 1
(quadratic):
Model 2
(linear):
where a and b are the coefficients from the 2nd order polynomial model (see Q3b).
In the Q3d.m file, solve the annual PFA in Borneo by applying the midpoint method to both models. Use a
step size of 0.001 years and the PFA value calculated for 1950 as the initial condition. The range of years
should span 1950 to 2100.
In a 1x2 subplot figure, plot the following:
PFA obtained in Q3a against the year as blue circles. [both panels]
PFA values obtained by solving Model 1 as a red line. [left panel]
PFA values obtained by solving Model 2 as a black line. [right panel]
Remember to include a legend. Use fprintf to provide a one-sentence explanation for why model 2 does not
provide an appropriate linear fit of the PFA data.
*You should have seven figure windows by the end of this task.
Poor Programming Practices [-2 Marks]
(Includes, but is not limited to, poor coding style or insufficient comments or
unlabeled figures, etc.)
(END OF ASSIGNMENT)

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/java2223/p/10321344.html
今日推荐