首页 > > 详细

辅导ENGR30003:R、R程序讲解、讲解留学生R语言、R程序讲解、讲解R、R语言讲解留学生

ENGR30003: Numerical Programming for Engineers
Semester 2, 2018 / Assignment 2
Marks : This assignment is worth 35% of the overall assessment for this course.
Due Date : Monday, 15th October 2018, 5:00pm, via a100a105a109a101a102a111a120 submission. You will lose
penalty marks at the rate of 10% per day or part day late, and the assignment will no be marked
if it is more than 5 days late.
1 Learning Outcomes
In this assignment you will demonstrate your understanding of solving engineering problems
using numerical computations and assessing particular algorithms. The objectives of this
assignment are to program algorithms for root-finding, solving systems of linear algebraic
equations, performing least-squares approximations and interpolations, regressing solutions and
solving a differential equation using different integration and differentiation schemes.
2 Rootfinding [9/35 marks]
qq
maxM
Figure 1: Difference in shock wave type for different wedge angles.
Imagine a wedge-shaped object flying through air at supersonic speeds (see Fig. 1). In
compressible flow theory (covered in MCEN90008 Fluid Dynamics), it is known that an oblique
shock wave forms at the front tip of this object under certain conditions.
The equation relating the wedge half-angle to the shock oblique angle, fl, and the Mach
number, M is given by
tan( )˘2cot(fl) M
2 sin2 (fl)¡1
M2( ¯cos(2fl))¯2 , (1)
where ˘1.4 is the ratio of specific heats. For a given M, as you keep increasing , there is a
critical angle, max where the shock becomes detached. We can also recast Eq. (1) into the
following form
f (fl)˘2cot(fl) M
2 sin2 (fl)¡1
M2( ¯cos(2fl))¯2 ¡tan( ) . (2)
Your tasks are the following:
© 2018 The University of Melbourne 1
35 10 15 20 25 30 35 40 45
-
0
10
20
30
40
50
60
70
80
90
Figure 2: ¡fl¡M diagram for M ˘5.0.
2.1 Analytical solution for ˘0– [1 mark]
For ˘0, i.e. the object would be a flat plate, show that two possible solutions for fl are
flL ˘arcsin
1
M

, flU ˘90– . (3)
flU and flL are usually called the strong shock and weak shock solutions, respectively. Even
though we can mathematically obtain two possible solutions, in reality, or physically, only the
weak shock solution occurs. Note also that in order for the solution to be physically realisable,
˙fl˙90–.
2.2 Graphical solution [2 mark]
Plot f (fl) vs fl for
a. M ˘1.5 and ˘5–, 10– and 15–
b. M ˘5.0 and ˘20–, 30– and 45–
Indicate how flU and flL change with and M. Can you identify from your plots the approximate
value of max?
PLEASE REMEMBER to change the angle from degrees to radians when you use sinusoidal
functions in your computer program.
2.3 C program to solve shock-wave equation [6 marks]
Your task is to write a C code that solves Eq. (2) using the Newton–Raphson method to find the
root of f (fl), regarding and M as parameters and solving for fl.
(a) Write your C program such that it uses the Newton–Raphson method to solve f (fl)˘0.
What values of flL and flU do you think might be appropriate to use as an initial guess? For
M ˘5.0 and ˘20–, you should find that
flL ˘29.80092...– , and flU ˘84.55625...–
(b) Extend your C program to find flU and flL values for M ˘5.0 and 0• • max. Remember
that for ˘0, flL ˘arcsin¡ 1M¢ and flU ˘90–. Plot values of on the horizontal axis and
corresponding values of fl on the vertical axis. Your solution to this part of the assignment
should look like Fig. 2. Note that you can plot your results obtained from your C code with
your program of choice, e.g. Matlab, Excel, etc.
© 2018 The University of Melbourne 2
(c) Use your computer program to solve f (fl)˘0 for M = 2.0, 3.0, 4.0, 6.0, 7.0, 8.0. Plot fl vs
for all the M’s. This plot is called the ¡fl¡M diagram and you will find it very useful if
you decide to do MCEN90008 Fluid Dynamics in the future.
The implementation for this task is to be done in a115a104a111a99a107a119a97a118a101a40a41 where input parameters are to
be read in from a105a110a95a115a104a111a99a107a46a99a115a118. The input file consists of three parts, as shown below:
M, theta , beta_l , beta_u ,gamma
5.0 ,20.0 ,0.0 ,0.0 ,1.4
M
5.0
M
2.0
3.0
4.0
6.0
7.0
8.0
The first two lines corresponds to the part (a) where for M = 5.0 and ˘200, you need to compute
the values of flL and flU. You will notice the initial values set here are 00 apiece so that you can
modify them to find the right initial guess to compute the angles. The next line corresponds to
part (b) where you will for M ˘5 evaluate the values of flL and flU for different values of
(increments of 10 from 00 up to max). The next set of lines corresponds to part (c) where you will
evaluate for different M, the values of flL and flU for different values of (increments of 10 from
00 up to max). Outputting the results of this task are to be done only for part (c) into
a111a117a116a95a115a104a111a99a107a46a99a115a118 in the format as shown below. This example only shows part of the results for
˘00,10 for the set of Mach numbers chosen (you can use this to validate your code). The output
of M, flU,flL is to be done up to 6 decimal places while as an integer:
M, theta , beta_lower , beta_upper
.
.
3.000000 ,0 ,19.471221 ,90.000000
3.000000 ,1 ,20.157561 ,89.649912
.
.In the following possible steps for coding up the methods are suggested.
a. Set up main program that does the following
• Allocate arrays for the functions f ni , f n¯1i , etc, where i ˘0,1,2,..., Nx (keep Nx a
parameter so that you can change it).
• Write the initial condition into the array f ni , and write to a file for later visualization.
• Set up loop over the number of timesteps you want to run (each with ¢t) - within this
loop you want to call your time integration routine.
• Write intermediate solutions to file for later visualization at several time instances.
b. Code up your time integration routine:
• if using the Euler upwind method, call a routine that computes @f@x based on the
function values at time level n.
Then evaluate the solution at the next time level n¯1 by using Eq. 10.
• if using the Lax–Wendroff method, call a routine that computes both @f@x and @2 f@x2 based
on the function values at time level n.
Then evaluate the solution at the next time level n¯1 by using Eq. 11.
c. Code up your routines for computation of the spatial derivatives @f@x and @2 f@x2 .
© 2018 The University of Melbourne 7
You will implement your routines in the function a119a97a118a101a101a113a110a40a41, reading in the values of c, Nx and
CFL from a105a110a95a119a97a118a101a101a113a110a46a99a115a118. This will allow you to compile your code just once and run it for
different values of c, Nx and CFL by just changing the infile. For code assessment, you will write
out the solutions from your Euler upwind and Lax–Wendroff versions to a111a117a116a95a119a97a118a101a101a113a110a95a69a85a46a99a115a118
and a111a117a116a95a119a97a118a101a101a113a110a95a76a87a46a99a115a118, respectively, the kth time the time loop executes (this depends on
what Nx,CFL are) in the following format (up to 6 decimal places).
x , f ( x )
0.000000 ,0.000000
0.010000 ,0.000394
0.020000 ,0.000907
.
.
.
The kth time will be read in from the infile from the parameter a111a117a116a95a105a116a101a114.
6.2 Tasks
Run your code until a time of t˘10 for both numerical methods (Euler upwind and
Lax–Wendroff) for the following cases:
• Chose two different resolutions ¢x, by setting Nx to 80 or 200.
• For each resolution, chose the timestep ¢t from the CFL number, defined as c¢t¢x ), using
CFL=1, 0.75 and 0.25.
Output your results for the time-levels t˘2,4,6,8,10 and plot the exact solution as well, which is
the same as the initial condition. How well does the solution at t˘10 agree with the exact
solution? Discuss:
• How does the agreement of the numerical prediction with the exact solution depend on the
grid resolution ¢x?
• How does the agreement of the numerical prediction with the exact solution depend on the
CFL number?
• What happens if you chose CFL>1 for either method, for example CFL=1.002?
7 Submission
This assignment, unlike assignment 1, consists of two parts
a. A project report, detailing any derivations and solutions and displaying the required graphs
b. C programs developed to solve some of the problems
You need to submit your programs and report for assessment; Submission of the report and
the code will be done via a100a105a109a101a102a111a120. You may discuss your assignment work during your
workshop, and with others in the class, but what gets typed into your programs and the report
must be individual work, not copied from anyone else. So, do not give a hard or soft copy of
your work to anyone; do not “lend” your “Uni backup” memory stick to others for any reason at
all; and do not ask others to give you their programs “just so that I can take a look and get some
© 2018 The University of Melbourne 8
ideas, I won’t copy, honest”. The best way to help your friends in this regard is to say a very firm
“no” when they ask for a copy of, or to see, your programs or report, pointing out that your “no”,
and their acceptance of that decision, is the only thing that will preserve your friendship. A
sophisticated program that undertakes deep structural analysis of C code identifying regions of
similarity will be run over all submissions in “compare every pair” mode. Students whose
programs or reports are so identified will be referred to the Student Center. See
a104a116a116a112a115a58a47a47a97a99a97a100a101a109a105a99a104a111a110a101a115a116a121a46a117a110a105a109a101a108a98a46a101a100a117a46a97a117 for more information.
7.1 Project Report
Your project report need not be a full technical report but should state all approximations made
and use figures of results to back up any conclusions. Be sure to include enough detail (using
appendices as necessary) so that your results could be reproduced by another researcher (or
yourself at a future date!) wishing to check or extend your findings. Your report will be primarily
assessed on the completeness of the results, and the visual/logical effectiveness of the manner in
which they are presented. Please type your report - scanned handwritten notes are sometimes
too difficult to read and mark and therefore will not be accepted.
7.2 C programs
The C codes are to be submitted on a100a105a109a101a102a111a120 where they would be tested on different inputs from
the ones you were provided to test your implementations.
7.2.1 Provided Code
• a109a97a105a110a46a99, where the parsing of data from command line is to be done and timing for each
task implemented.
• a116a97a115a107a115a46a99, where you will implement four functions a115a104a111a99a107a119a97a118a101a40a41 (Question 2),
a108a105a110a97a108a103a98a115a121a115a40a41 (Question 4), a105a110a116a101a114a112a40a41 (Question 5) and a119a97a118a101a101a113a110a40a41 (Question 6), one for
each task.
• a116a97a115a107a115a46a104, which acts as a header file to link the C file to the main file. You may edit this to
add any a115a116a114a117a99a116’s or the input arguments to the functions.
• Input files a105a110a95a115a104a111a99a107a46a99a115a118 (Question 2), a105a110a95a108a105a110a97a108a115a121a115a46a99a115a118 (Question 4), a105a110a95a105a110a116a101a114a112a46a99a115a118
(Question 5) and a105a110a95a119a97a118a101a101a113a110a46a99a115a118 (Question 6) which you must use as input during
execution of your program. During your submission, your code will be tested on different
infiles from the ones you were provided. Please make sure any data structures used to read
in these infiles are dynamically allocated to avoid any errors during runtime.
Remember to fill in your details in each file you write, such as the student name and student
number. Key points about your code for this assignment you need to understand are as follows:
• For the purposes of the report, you can output as many files or terminal outputs as you
need. These outputs can be used to generate graphs/plots and values for the different tasks.
• Once you have all information you need for the report, your code must be made submission
worthy i.e. only output the outfiles described above (5 outfiles are expected). This means
your code must not expect user input once you execute it, all inputs would come from the
infiles or the terminal before execution.
• You have to parse the command line arguments (all infiles and any command line values)
i.e. no hardcoding the names of the infiles or the value for interpolation task. This is
because we will be using our own infiles, with different filenames and different locations.
© 2018 The University of Melbourne 9
• Plan before you write your code. Cover all possibilities regarding different inputs.
Dynamically allocating structures for the infile contents is a must so that for infiles with
more or less entries don’t end up giving you errors during submission.
7.2.2 Submitting on Dimefox
All submissions must be made through the a115a117a98a109a105a116 program. Assignments submitted through
any other method will not be marked. Transfer your files to your home drive on dimefox. Check
the transfer was successful by logging into dimefox and doing the a108a115 command on the terminal.
Perform. the following set of commands on the terminal from your home location on dimefox
(making the right folders and transfering the files in the right location):
a109a107a100a105a114 a69a78a71a82a51a48a48a48a51
a99a100 a69a78a71a82a51a48a48a48a51
a109a107a100a105a114 a65a50
a99a100 a65a50
a99a112 a46a46a47a46a46a47a42a46a99 a46
a99a112 a46a46a47a46a46a47a42a46a104 a46
a99a112 a46a46a47a46a46a47a42a46a99a115a118 a46
a99a112 a46a46a47a46a46a47a42a46a112a100a102 a46
Remember to check this folder contains only the .c or .h files (if you use multiple c files and h
files) you need for the assignment and the CSV data file. Then try compiling your code using a103a99a99
on the terminal from the a65a50 folder, to see if it works. The following compilation procedure must
return no errors or warnings:
a103a99a99 a45a87a97a108a108 a45a115a116a100a61a99a57a57 a42a46a99 a45a111 a101a120a101a99 a45a108a109
You can test your compiled code then using:
a46a47a101a120a101a99 a105a110a95a115a104a111a99a107a46a99a115a118 a105a110a95a108a105a110a97a108a115a121a115a46a99a115a118 a105a110a95a105a110a116a101a114a112a46a99a115a118 a53 a105a110a95a119a97a118a101a101a113a110a46a99a115a118
There are 5 command line arguments here, one for each of the 4 coding functions. The argument
number 4 (a53) is part of the interpolation task: the value of xo at which the interpolated value is to
be outputted. Once your code works for the provided infiles, it would help you if you changed the
infiles and the 4th argument to different values and see if the code still works and outputs
acceptable results. If this works, your code is now submission worthy. Finally, you will submit
your files using the command a115a117a98a109a105a116 as follows:
a115a117a98a109a105a116 a69a78a71a82a51a48a48a48a51 a65a50 a42a46a99 a42a46a104 a42a46a112a100a102
Do NOT submit your infiles as this would likely corrupt your submission and would take time to
fix. Wait for a few minutes and then carry out the verify and check steps:
a118a101a114a105a102a121 a69a78a71a82a51a48a48a48a51 a65a50 a62 a102a101a101a100a98a97a99a107a46a116a120a116
a110a97a110a111 a102a101a101a100a98a97a99a107a46a116a120a116
Look through this text file to check (a) your program compiled (b) it executed without error.
Please read a109a97a110 a115a117a98a109a105a116 on a100a105a109a101a102a111a120 for confirmation about how to use a115a117a98a109a105a116, especially how to
a118a101a114a105a102a121 your submission. No special consideration will be given to any student who has not used
© 2018 The University of Melbourne 10
a115a117a98a109a105a116 properly.
You must also check that you have no memory leaks in your code as loss of memory from your
implementation will result in deductions. You can use a118a97a108a103a114a105a110a100 for this as follows:
a118a97a108a103a114a105a110a100 a46a47a101a120a101a99 a105a110a95a115a104a111a99a107a46a99a115a118 a105a110a95a108a105a110a97a108a115a121a115a46a99a115a118 a105a110a95a105a110a116a101a114a112a46a99a115a118 a53 a105a110a95a119a97a118a101a101a113a110a46a99a115a118
This should output a leak summary such as the best case shown below. It must be pointed out
that the runtime with this takes longer as compared with direct execution. Plan your submission
accordingly.
a61a61a51a56a56a55a61a61 a72a69a65a80 a83a85a77a77a65a82a89a58
a61a61a51a56a56a55a61a61 a105a110 a117a115a101 a97a116 a101a120a105a116a58 a48 a98a121a116a101a115 a105a110 a48 a98a108a111a99a107a115
a61a61a51a56a56a55a61a61 a116a111a116a97a108 a104a101a97a112 a117a115a97a103a101a58 a53a51 a97a108a108a111a99a115a44 a53a51 a102a114a101a101a115a44 a53a54a44a57a50a49a44a49a54a56 a98a121a116a101a115 a97a108a108a111a99a97a116a101a100
a61a61a51a56a56a55a61a61 a65a108a108 a104a101a97a112 a98a108a111a99a107a115 a119a101a114a101 a102a114a101a101a100 a21 a110a111 a108a101a97a107a115 a97a114a101 a112a111a115a115a105a98a108a101
All submissions should be in C99, and use no functions outside of the C standard library and
maths library. Some key points to consider about your submission and verification are outlined
here:
• Submissions that can not be compiled or run by a115a117a98a109a105a116 system will receive zero marks
for the programming part.
• Submissions are also limited to a maximum runtime of 200 seconds and maximum file size
per task of 2 MB. It would help if you don’t write any additional files through your code. If
it is absolutely necessary, then make sure the files do not exceed 2 MB individually. This
would give errors during your submission.
• a102a101a101a100a98a97a99a107a46a116a120a116 will contain feedback for individual tasks as with the first assignment. For
question 6, you will receive feedback on both files individually. Since the contents of the
infiles used for your code testing by the markers will not be disclosed to you, the feedback
will only say whether your output was correct or not.
• Because of the above point, you can work on each task individually and submit your code
with just one or two tasks implemented. The feedback will skip over tasks not implemented
and only look at the outfile of the tasks implemented. So please use a115a117a98a109a105a116 as frequently
as possible. Submitting your code for the first time a day before the deadline is not ideal for
you or us.
• You must parse all command line arguments, even if you do submit just one or two tasks to
see if your implementation works. The arguments will be in the exact sequence as given in
the execution statement above. As an example, if you want to test only the interpolation
task, your code will have to parse the 3rd and 4th arguments as all 5 arguments will be
present during execution. The takeaway is that you should ensure you are associating the
right infile to the right task.
• Only your last submission is stored in the system i.e. everytime you use a115a117a98a109a105a116, the new
submission overwrites the previous version. Keep a backup of your previous versions
somewhere safe in case your latest submission works worse than the previous.
© 2018 The University of Melbourne 11
8 Getting Help
There are several ways for you to seek help with this assignment. First, check the Assignment 2
Frequently Asked Questions wiki in the LMS (subsection Assignments). It is likely that your
question has been answered here already. You may also discuss the assignment on the
“Assignment 2” discussion board. However, please do not post any source code on the discussion
board. You may also ask questions during the workshops or send me (Professor Sandberg,
a114a105a99a104a97a114a100a46a115a97a110a100a98a101a114a103a64a117a110a105a109a101a108a98a46a101a100a117a46a97a117) an email directly.
Note: Students seeking extensions for medical or other “outside my control” reasons should
email Professor Sandberg, a114a105a99a104a97a114a100a46a115a97a110a100a98a101a114a103a64a117a110a105a109a101a108a98a46a101a100a117a46a97a117 as soon as possible after those
circumstances arise.
© 2018 The University of Melbourne 1

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!