# ENGR30003代写、代做Programming、C/C++编程语言调试、c+%2

转载
2019-10-20 09:53:45

ENGR30003: Numerical Programming for EngineersSemester 2, 2019 /
Assignment 2Marks : This assignment is worth 35 of the overall
assessment for this course.Due Date : Monday, 21st October 2019,
5:00pm, via submission. You will losepenalty marks at the rate of
10 per day or part day late, and the assignment will no be markedif
it is more than 5 days late.1 Learning OutcomesIn this assignment
you will demonstrate your understanding of solving engineering
problemsusing numerical computations and assessing particular
algorithms. The objectives of thisassignment are to program
algorithms for root-finding, solving systems of linear
algebraicequations, performing least-squares approximations and
interpolations, regressing solutions andsolving a differential
equation using different integration and differentiation schemes.2
Rootfinding [9/35 marks]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). Incompressible flow theory
(covered in MCEN90008 Fluid Dynamics), it is known that an
obliqueshock wave forms at the front tip of this object under
certain conditions.The equation relating the wedge half-angle θ to
the shock oblique angle, β, and the Machnumber, M is given bywhere
γ = 1.4 is the ratio of specific heats. For a given M, as you keep
increasing θ, there is acritical angle, θmax where the shock
becomes detached. We can also recast Eq. (1) into thefollowing
formYour tasks are the following:© 2019 The
University of Melbourne 1Figure 2: θ
−β− M diagram for M = 5.0.For θ
= 0, i.e. the object would be a flat plate, show that two possible
solutions for β areβL =
arcsinµ1M¶, βU = 90. (3)βU and
βL are usually called the strong shock and weak shock solutions,
respectively. Eventhough we can mathematically obtain two possible
solutions, in reality, or physically, only theweak shock solution
occurs. Note also that in order for the solution to be physically
realisable,θ 2.2 Graphical solution [2 mark]Plot f (β) vs β fora. M
= 1.5 and θ = 5, 10 and 15b. M = 5.0 and θ = 20, 30 and 45Indicate
how βU and βL change with θ and M. Can you identify from your plots
the approximatevalue of θmaxPLEASE REMEMBER to change the angle
from degrees to radians when you use sinusoidalfunctions 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 theroot of f (β),
regarding θ and M as parameters and solving for β.(a) Write your C
program such that it uses the Newton–Raphson
method to solve f (β) = 0.What values of βL and βU do you think
might be appropriate to use as an initial guess ForM = 5.0 and θ =
20, you should find thatβL = 29.80092..., and βU = 84.55625...(b)
Extend your C program to find βU and βL values for M = 5.0 and 0 ≤
θ ≤ θmax. Rememberthat for θ = 0, βL =
arcsin¡1M¢ and βU = 90. Plot
values of θ on the horizontal axis andcorresponding values of β on
the vertical axis. Your solution to this part of the
assignmentshould look like Fig. 2. Note that you can plot your
results obtained from your C code withyour program of choice, e.g.
Matlab, Excel, etc.© 2019 The University of
Melbourne 2(c) Use your computer program to solve f (β) = 0 for M =
2.0, 3.0, 4.0, 6.0, 7.0, 8.0. Plot β vs θfor all the M’s. This plot
is called the θ −β− M diagram
and you will find it very useful ifyou decide to do MCEN90008 Fluid
Dynamics in the future.The implementation for this task is to be
done in where input parameters are tobe read in from. The input
file consists of three parts, as shown below:M, theta , be ta_ l ,
beta_u ,gammaThe first two lines corresponds to the part (a) where
for M = 5.0 and θ = 200, you need to computethe values of βL and βU
. You will notice the initial values set here are 00 apiece so that
you canmodify them to find the right initial guess to compute the
angles. The next line corresponds topart (b) where you will for M =
5 evaluate the values of βL and βU for different values of
θ(increments of 10from 00 up to θmax). The next set of lines
corresponds to part (c) where you willevaluate for different M, the
values of βL and βU for different values of θ (increments of 10from
00 up to θmax). Outputting the results of this task are to be done
only for part (c) into in the format as shown below. This example
only shows part of the results forfor the set of Mach numbers
chosen (you can use this to validate your code). The outputof M, βU
,βL is to be done up to 6 decimal places while θ as an integer:M,
theta , beta_ lower , beta_upper3.000000 ,0 ,19.471221
,90.0000003.000000 ,1 ,20.157561 ,89.6499124.000000 ,0 ,14.477513
,90.0000004.000000 ,1 ,15.131265 ,89.719941You must dynamically
allocate space for the Mach numbers so that your implementation
maywork for a different set of M. For each Mach number, upon
increasing θ by 10, you will reach themaximum θ beyond which the
solutions of β are not physically relevant. You will write to
fileonly up to this maximum θ per Mach number.©
2019 The University of Melbourne 33 Regression [4/35 marks]Here, an
alternative way of solving a Least Squares Problem is considered.
Recall from thelecture that(4)is the system of equations for linear
regression yˆ = ax b.Show that:By considering Eq.
5, when will linear regression fail to find a solution4 Linear
Algebraic Systems [5/35 marks]Consider the following tri-diagonal
system:© 2019 The University of Melbourne 4Thus
the solution to the original tri-diagonal matrix can be written
asThe algorithm outlined above is called the Thomas algorithm. It
is a very efficient method forsolving linear tri-diagonal
systems.Write a C code using the Thomas algorithm to solve the
tri-diagonal system shown in Eq. 6.Since the tri-diagonal system is
a banded matrix, you need not store all the zeros! Instead,
yourcode should take as an input the vectors ai, bi, ci and Qi. The
output from your C code should bethe solution vector xi.Use your
code to solve the following tri-diagonal system(8)You will
implement the code for this task in the function, where you will
read inas an input the vectors ai, bi, ci and Qi from the file. The
output from yourimplementation should be the solution vector xi,
written out to (up to 6decimal places). Your implementation should
allocate dynamically the space for the values of ai,bi, ci and Qi
such that your implementation would work for different problem
sizes as well.5 Interpolation [4/35 marks]For this task, you will
perform a cubic spline interpolation on the data provided in the
file. First, plot the data (using MATLAB or Excel) in order to get
an idea of thebehaviour f (x) should have. Next, write C code that
uses cubic splines in order to estimate thefunction f (x) that cuts
through the data. You will then use your code to calculate the
value(s) off (x) at xo = 4, where xo is to be input at runtime from
stdout. You will implement your method in, reading the values of x
and f (x) from the file and outputting thevalues of the
interpolated value to in the following format (up to 6
decimalplaces).xo , f ( xo )4.000000 ,0.2346554.000000 ,1.107865The
output provided above is an example and does not constitute the
solution. There may bemore than 1 solution possible here and you
must be able to identify the correct interval(s) tocompute the
interpolated value. For the C implementation, you must dynamically
allocate spacefor x, f (x) and write your code such that it can
work for a different set of input data and differentxo. Finally,
you must plot the interpolated function using either MATLAB or
Excel. How does theinterpolated function look compared with the
actual datapoints© 2019 The University of
Melbourne 56 Differentiation, differential equations [13/35
marks]Write a C program that solves the modified wave equationon
the interval x = [0;1], and for times 0 ≤ t ≤ 0.2, using the phase
speed c = 1.Most transport equations can also be written
as∂f∂t= RHS(f ) (10)where RHS
denotes the ‘right-hand-side’ of the equation to be solved,
containing all spatialderivatives, in this case
−c∂f∂x.The wave
equation is to be solved on the spatial interval 0 ≤ x ≤ 1, that is
discretized usingNx 1 points xi, with i = 0,1,2,..., Nx. The
equidistant grid spacing therefore is x = 1/Nx.In order to
discretize the time derivative
∂f∂t, use the second-order
accurate Runge–Kutta, (11)where n is the time
index so that fniis the function value at time level n at point xi
and fn1the function value at time level n1 at point xi, superscript
n0.5 denotes an intermediate(time) level, and t is the numerical
timestep for the time integration.Two different finite-difference
approximations for the spatial derivative are to be coded
up:• The first-order accurate upwind scheme:for i
= 1,..., NxFor i = 0, use the boundary stencil•
The second-order accurate central scheme:for i = 1,..., Nx
−1For i = 0, use the boundary stenciland for i =
Nx use the boundary stencilThe initial condition for f is0 ≤ x
0.125 ≤ x ≤ 0.375 → f (x,t = 0) =
0.5[1−cos{8π(x−0.125)}]0.375
© 2019 The University of Melbourne 66.1 Suggested
Code StructureIn 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,
etc, where i = 0,1,2,..., Nx (keepNx a parameter so that you can
change it).• Write the initial condition into the
array fni, and write to a file for later
visualization.• Set up loop over the number of
timesteps you want to run (each with t) - within thisloop you want
to call your RK2 routine.• Write intermediate
solutions to file for later visualization at several time
instances.b. Code up your RK2 routine:spatial derivatives are
computed based on the function values at time level spatial
derivatives are computed based on the function values at
intermediate levelc. Code up your ‘RHS’ routine. In this routine,
implement the two options for taking thespatial derivative, the
upwinding scheme and the central scheme.For your code to run
stably, your time steps need to satisfy the so-called CFL
condition,specifying ENGR30003代写、代做Programming、C/C%that ctx≤ 1.You
will implement your routines in the function , reading in the
values of c, Nxand CFL from . This will allow you to compile your
code just once and run it fordifferent values of c, Nx and CFL by
just changing the infile. For code assessment, you will writeout
the solutions from your two finite-difference approximations
versions to and , 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.0000000.010000
,0.0003940.020000 ,0.000907The kth time will be read in from the
infile from the parameter .6.2 TasksRun your code until a time of t
= 0.2 for both finite-difference approximations (1st-order
upwindand 2nd order central) for the following
cases:© 2019 The University of Melbourne
7• Chose two different resolutions x, by setting
Nx to 80 or 200.• For each resolution, chose the
timestep t from the CFL number, using CFL=1, 0.75 and0.25.Output
your results for the time-levels t = 0.05,0.1,0.15,0.2 and plot the
exact solution as well,which is the same as the initial condition,
shifted by c ·t in increasing x. How well does thesolution at t =
0.2 agree with the exact solution Discuss:• How
does the agreement of the numerical prediction with the exact
solution depend on thegrid resolution x• How does
the agreement of the numerical prediction with the exact solution
depend on theCFL number• What happens if you chose
CFL>1 for either method, for example CFL=1.0027
SubmissionThis assignment, unlike assignment 1, consists of two
partsa. A project report, detailing any derivations and solutions
and displaying the required graphsb. C programs developed to solve
some of the problemsYou need to submit your programs and report for
assessment; Submission of the report andthe code will be done via .
You may discuss your assignment work during yourworkshop, and with
others in the class, but what gets typed into your programs and the
reportmust be individual work, not copied from anyone else. So, do
not give a hard or soft copy ofyour work to anyone; do not “lend”
your “Uni backup” memory stick to others for any reason atall; and
do not ask others to give you their programs “just so that I can
take a look and get someideas, 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.
Asophisticated program that undertakes deep structural analysis of
C code identifying regions ofsimilarity will be run over all
submissions in “compare every pair” mode. Students whoseprograms or
reports are so identified will be referred to the Student Center.
See for more information.7.1 Project ReportYour project report need
not be a full technical report but should state all approximations
madeand use figures of results to back up any conclusions. Be sure
to include enough detail (usingappendices as necessary) so that
your results could be reproduced by another researcher (oryourself
at a future date!) wishing to check or extend your findings. Your
report will be primarilyassessed on the completeness of the
results, and the visual/logical effectiveness of the manner inwhich
they are presented. Please type your report - scanned handwritten
notes are sometimestoo difficult to read and mark and therefore
will not be accepted.7.2 C programsThe C codes are to be submitted
on where they would be tested on different inputs fromthe ones you
were provided to test your implementations.© 2019
The University of Melbourne 87.2.1 Provided Code, where the parsing
of data from command line is to be done and timing for eachtask
implemented.where you will implement four functions (Question
2),which acts as a header file to link the C file to the main file.
You may edit this toadd any or the input arguments to the
functions.which you must use as input duringexecution of your
program. During your submission, your code will be tested on
differentinfiles from the ones you were provided. Please make sure
any data structures used to readin 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
studentnumber. 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 youneed. 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 submissionworthy i.e. only output the outfiles
described above (5 outfiles are expected). This meansyour code must
not expect user input once you execute it, all inputs would come
from theinfiles 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 isbecause we will be using
our own infiles, with different filenames and different
locations.• 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
withmore or less entries don’t end up giving you errors during
submission.7.3 Running on DimefoxYou must first transfer your files
from your home computer to the Dimefox server using the protocol.
Then, log into dimefox and transfer the files to a relevant folder:
perform thefollowing set of commands on the terminal from your home
location on dimefox (making the rightfolders and transfering the
files in the right location):© 2019 The University
of Melbourne 9Remember to check this folder contains only the .c or
.h files (if you use multiple c files and hfiles) you need for the
assignment and the PDF report you wish to submit. Then try
compilingyour code using on the terminal from the folder, to see if
it works. The followingcompilation procedure must return no errors
or warnings:You can test your compiled code then using:There are 5
command line arguments here, one for each of the 4 coding
functions. The argumentnumber 4 () is part of the interpolation
task: the value of xo at which the interpolated value is tobe
outputted. Once your code works for the provided infiles, it would
help you if you changed theinfiles and the 4th argument to
different values and see if the code still works and
outputsacceptable results. If this works, your code is now
submission worthy.7.4 Submitting on DimefoxAll submissions must be
made through the program. Assignments submitted throughany other
method will not be marked. Transfer your files to your home drive
on dimefox. Checkthe transfer was successful by logging into
dimefox and doing the s command on the terminal.Once you’ve tested
the code by running on Dimefox using the approach described in
Running onDimefox section, you can then submit your files using the
command as follows:Do NOT submit your infiles as this would likely
corrupt your submission and would take time tofix. Wait for a few
minutes and then carry out the verify and check steps:Look through
this text file to check (a) your program compiled (b) it executed
without error.Please read for confirmation about how to use,
especially how to your submission. No special consideration will be
given to any student who has not used properly.You must also check
that you have no memory leaks in your code as loss of memory from
yourimplementation will result in deductions. You can use for this
as follows:It must be pointed out that will take longer time to run
compared with the normalexecution, so, plan your submission
accordingly. Incase your submission fails to pass the memorycheck,
you will lose marks. There are two potential areas where you can
lose marks: runtimeerror messages and heap/leak summary. Examples
of runtime error messages include:Happens when you use a variable
that has not© 2019 The University of Melbourne
10been defined or does not exist anymore or initialised. Happens
whenusing an uninitialised variable to perform operations: Happens
when trying to scan or write to file a variableto memory which you
do not have access to.All submissions should be in C99, and use no
functions outside of the C standard library andmaths library. Some
key points to consider about your submission and verification are
outlinedhere:• Submissions that can not be
compiled or run by system will receive zero marksfor the
programming part.• Submissions are also limited to
a maximum runtime of 200 seconds and maximum file sizeper task of 2
MB. It would help if you don’t write any additional files through
your code. Ifit is absolutely necessary, then make sure the files
do not exceed 2 MB individually. Thiswould give errors during your
submission.• Since each task can be assessed
individually, you can work submit your code with just oneor two
tasks implemented. The feedback will skip over tasks not
implemented and onlylook at the outfile of the tasks
implemented.• Only your last submission is stored
in the system i.e. everytime you use, the newsubmission overwrites
the previous version. Keep a backup of your previous
versionssomewhere safe in case your latest submission works worse
than the previous.8 Getting HelpThere are several ways for you to
seek help with this assignment. First, check the Assignment
2Frequently Asked Questions wiki in the LMS (subsection
Assignments). It is likely that yourquestion 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 discussionboard. You may also ask questions during the
workshops or send me (Professor Sandberg, an email directly.Note:
Students seeking extensions for medical or other “outside my
control” reasons shouldemail Professor Sandberg, as soon as
possible after thosecircumstances arise.© 2019 The
University of Melbourne 11

程序解答，请加扣扣： 9 9 5 1 5 6 8 1 或 WX：codehelp

程序解答，请加扣扣： 9 9 5 1 5 6 8 1 或 WX：codehelp

前一篇: 他找女朋友了``
后一篇:CSSE1001/7030代做、代写Python程序...

## 评论

重要提示：警惕虚假中奖信息