Status: Individual
Hurdle: There is no hurdle on assignment
Weighting: 10% Word limit: No limit
MCD 4140: Computing for Engineers
Assignment Trimester 2, 2018
Due date: By 12.00pm on Monday 27/08/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. Do not use close all, clear all, clc in any individual mfiles.
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 (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.)
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. 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
1 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.
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
- You can ask questions in the Discussion Board on Moodle
- Hints and additional instructions are provided as comments in the assignment template m-files
- Hints may also be provided during lectures
- 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.
- 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.
- The m-file templates contain comments and sections only as a guide. You do not need to follow its
structure.
- 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
2 of 8
QUESTION 1
[5 MARKS]
Background
“Exoplanets are planets beyond our own solar system. Thousands have been discovered in the past two decades, mostly with NASA’s Kepler Space Telescope.
These worlds come in a huge variety of sizes and orbits. Some are gigantic planets hugging close to their parent stars; others are icy, some rocky. NASA and other agencies are looking for a special kind of planet: one that’s the same size as Earth, orbiting a sun-like star in the habitable zone.
Most exoplanets have been discovered by the Kepler Space
Telescope, an observatory that began work in 2009 and is expected to finish its mission in 2018, once it runs out of fuel. As of mid-March 2018, Kepler has discovered 2,342 confirmed exoplanets and revealed the existence of perhaps 2,245 others. The total number of planets discovered by all observatories is 3,706.”
Source: space.com (29th March 2018) | Credit: NASA
You are provided with three csv files: 1. exoplanets_numerical.csv
2. exoplanets_names.csv
3. exoplanets_types.csv
Source: http://exoplanetarchive.ipac.caltech.edu/ (2nd April 2018)
The header definitions are:
- loc_id = Local identifier value
- pl_pnum: Number of planets in the planetary system
- pl_orbper: Time the planet completely orbit around the host star or system [days]
- pl_orbsmax: Longest diameter of an elliptic orbit (AU)
- pl_orbeccen: Eccentricity
- pl_orbincl: Angular distance of the orbital plane from the line of sight [deg]
- st_rad: Star radius [solar radii]
- st_dist: Distance to the planetary system in units of parsecs from Earth [pc]
- st_teff: Temperature of star modelled by as an electromagnetically-radiating black body (K)
- pl_disc: Year the planet was discovered
- pl_hostname: Host star name
- st_spstr: Classification of the star based on the Morgan-Keenan system
The data in the files are all related such that the 1st element in each file is associated with the 1st planet in exoplanets_names.csv. Open the csv files to check the data of the 1st planet entry.
loc_id = 1, pl_num = 1, pl_orbper = 326.03, …, pl_hostname = 11 Com, st_spstr = K0 III
MCD4140 Assignment
3 of 8
Q1a
In the Q1a.m file, all three .csv files have been imported using the importdata() function. The exoplants_numerical.csv data file is imported as a structure while exoplanets_names.csv and exoplanet_types.csv data are imported as cells1. Create vectors for the local identifiers, the star radius, the star temperature, the distances to the planetary system, and the year the planet was discovered. It is important to note that the cells will contain the header text and therefore there will be an offset of 1 when comparing to the vectors containing numerical data.
Plot the distances against the local identifiers as black circles with the vertical axis logarithmically scaled, and the horizontal axis linearly scaled. Use units of kilometers (km) rather than parsecs (pc).
Note: 1 pc = 3.26 light years and 1 light year = 9.461×1012 km. Hint: See “help plot” for axis scaling documentation.
*You should have one figure window by the end of this task.
Q1b
In the Q1b.m file, plot the distances listed below on the same figure created in Q1a to provide some perspective on the distances of the exoplanets from Earth. The distances should be drawn as horizontal lines spanning the entire range of the local identifiers. The line specification is provided in square brackets below. Remember to label your plot and place the legend in the “best” location.
- Distance from Earth to Sun = 149.6×106 km
- Distance from Earth to Saturn = 1.2×109 km
- Distance from Earth to Neptune = 2.7×109 km
[red continuous line] [blue continuous line] [green continuous line]
Use fprintf to print a statement containing the name of the nearest exoplanet and its distance from Earth. It should look similar to the following:
Nearest exoplanet: ??? Corresponding distance: ??? pc
*You should still have one figure window by the end of this task.
Q1c
In the Q1c.m file, determine the number of planets discovered per year. Plot the number of planets discovered against the year as black squares with the vertical axis logarithmically scaled, and the horizontal axis linearly scaled.
Hint: See “help unique” for value extraction but with no repetitions. *You should have two figure windows by the end of this task.
1 Cells are similar to matrices except it may contain both numerical data and strings inside a single cell.
Source: https://au.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-array.html
MCD4140 Assignment
4 of 8
There
are two ways to refer to the elements of a cell array. Enclose indices in smooth parentheses, (), to refer to sets
of cells–for example, to define a subset of the array. Enclose indices in curly braces, {}, to refer to the text,
numbers, or other data within individual cells.
Q1d
In the Q1d.m file, determine which years had 100 or more planet discoveries. Update the previous figure to plot these data points as red squares. Also, print the years which satisfy this condition and the corresponding number of planets discovered into the command window. Use column widths of 10. The table should look similar to the following:
Year #Planets
- 2011 136
- 2012 137
…. …
*You should still have two figure windows by the end of this task.
Q1e
In the Q1e.m file, create a new figure and plot the star’s temperature against the star’s radius as black circles on logarithmic axes. The star can be categorised as either A, B, F, G, K or M-types. The first letter in the st_spstr field of exoplanets_types.csv determines the classification.
Update
- A-type: coloured [0.64, 0.73, 1]
- B-type: coloured [0.7, 0.88, 0.89]
- F-type: coloured [0.79, 0.51, 0.75]
- G-type: coloured [1, 1, 0.6]
- K-type: coloured [1, 0.81, 0.59]
- M-type: coloured [1, 0.62, 0]
- Unknown star types remain uncoloured.
Place the legend in the southeast corner.
Note: the colour matrix is already provided to you in the m-file.
Note: the star type string is already provided to you and the index matrix has already been preallocated for you in the m-file.
Hint: you can reference the contents of the cell using {}, and the element using (). E.g. exotype{1}(1) would give you ‘K’ since the first entry of the exotype cell is ‘K0 III’.*You should have three figure windows by the end of this task.
the newly created figure to fill the data points according to the following:
MCD4140 Assignment
5 of 8
QUESTION 2
[5 MARKS]
The volume of a spherical tank used for liquid storage is given by the following integral:
16 1 1
𝑉= 3 𝑟3∫1+𝑥2𝑑𝑥
0
Here r is the radius of the sphere and x is the variable being integrated.
Q2a
In the Q2a.m file, write an m-file that evaluates this integral using the following numerical integration methods with 𝑟 = 0.5 m:
- Composite Trapezoidal method, and
- Composite Simpson’s 1/3 rule
Start with the minimum number of points required to perform the integration in each method. Continue to increase the number of points until the approximated volume achieves an accuracy of 8 decimal places matching the volume value obtained using MATLAB’s integral() function.
Use fprintf to print the iteration number, number of points, current volumetric approximation and the absolute error, but only when the accuracy of the estimation has improved by at least a decimal place. An example of this is shown below, with the decimal places bolded and underlined for clarity (you do not need to bold and underline the values in your MATLAB answers):
Composite Trapezoidal Rule:
iter pts vol_approx error DP1 2 0.50000000 0.02359878 1 2 3 0.51666667 0.00693211 2 6 7 0.52282718 0.00077160 3 ? ? ?????????? ?????????? ?
Composite Simpson’s 1/3 Rule:
iter pts vol_approx error DP1 3 0.52222222 0.00137655 2 2 5 0.52359477 0.00000400 5 ? ? ?????????? ?????????? ?
Note: The widths used in the above columns were 6, 6, 12, 12, and 6 (left to right).
Note: The error is the absolute difference between the approximated volume and actual volume.
Hint: The accuracy of the decimal places can be calculated using a combination of log10() and other inbuilt MATLAB functions.*You should still have three figure windows by the end of this task.
MCD4140 Assignment
6 of 8
Q2b
The relationship between the volume of liquid and liquid height in the tank is:
𝑉 = 𝜋 𝑟 h 2 − 13 𝜋 h 3
In the Q2b.m file, determine the height of the liquid if the tank is 90% full in volume (based on the total volume obtained via MATLAB’s integral() function used in Q2a), using the Newton-Raphson method with a precision = 10-8. Plot the root-finding equation as a black continuous line to determine your initial guess for h.
Use fprintf to display the height of the liquid for 90% volume in the command window and the number of iterations it took to achieve the required precision, similar to the following:
Height of liquid for 90% volume: ??? m Initial guess of h=??? requires ? iterations
*You should have four figure windows by the end of this task.
Q2c
The tank which is 90% filled in volume (based on the total volume obtained via MATLAB’s integral() function used in Q2a), is now allowed to drain at a constant flow rate from an outlet pipe connected at the bottom. In the Q2c.m file, compute the height of the liquid over time as the tank drains by solving the following differential equation using Heun’s method:
𝑑h= 𝑞
𝑑𝑡 2𝜋𝑟h − 𝜋h2
where q represents the flow rate. If the outgoing flow rate is -0.001 m3/sec, plot the height of the liquid in the tank against time as a continuous red line using the following properties:
- t=0 s to t=450 s with a time step of 0.1 s.
- t=450 s to t=500 s with a time step of 0.0001.
The time taken for the tank to drain can be calculated using time = volume/flow rate. Solve for the time for when the tank becomes empty using 90% total volume (based on the total volume obtained via MATLAB’s integral() function used in Q2a), as the starting time. Use fprintf to print this time and provide a one- sentence explanation for why results from Heun’s method displays peculiar behaviour after this time in the plot. The print should be similar to the following:
Time to drain: ??? s
Explanation: Odd behavior is shown near t=500 s because …*You should have five figure windows by the end of this task.
where h represents the height of the liquid.
MCD4140 Assignment
7 of 8
Q2d
You perform some experiments on the drained liquid to test for its viscosity as a function of temperature. The current equipment does not allow for temperatures greater than 400°C. However, you require this information for your theoretical work. The measured data is shown below:
You are unsure of which model would best fit the above data. Therefore, you start by performing five polynomial fits to the data (orders 2 to 6) to determine the viscosity of the liquid at 400°C. In the Q2d.m file, plot the measured viscosity against temperature as black diamonds. Then plot all five fitted polynomials on the same plot as continuous lines using the following colour order (for polynomials 2 to 5, respectively): cyan, red, green, blue, and magenta.
Your fitted polynomials should be 1000 evenly spaced points between the smallest and largest measured temperature values (inclusive). Print a table that contains the polynomial order and estimated viscosity at 400°C, similar to the following:
Viscosity at 400 degrees Order Viscosity 2 0.91 3 -1.40 4 ???
*You should have six figure windows by the end of this task.
Q2e
Unfortunately, the fitted polynomials provide a horrible estimate for viscosity at 400°C. A colleague suggests using the power model instead. In the Q2e.m file, linearise the temperature and viscosity data to determine the power equation. Plot this non-linear fit (using the same range specified in Q2d) on the same plot created in Q2d as a black continuous line with a thickness of 2. Remember to include a legend – you may manually type in the entries of the legend. E.g. legend(‘measured data’, ‘poly=2’, ‘poly=3’, …)
Use fprintf to print a statement regarding the viscosity of the liquid at a temperature of 400°C, similar to the following:
Temperature of 400 degrees gives viscosity of ??? Ns/m^2
*You should still have six 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)
Temperature (°C) |
26.67 |
50.58 |
93.33 |
120.55 |
148.89 |
210.55 |
248.53 |
315.56 |
Viscosity, Ns/m2 |
1.35 |
0.33 |
0.085 |
0.045 |
0.012 |
0.00099 |
0.00084 |
0.00075 |
MCD4140 Assignment
8 of 8