首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导Python编程设计、讲解data程序、Python语言编程辅导 解析Haskell程序|讲解R语言程序
项目预算:
开发周期:
发布时间:
要求地区:
CR3 (Submission phase)
Submission phase
Instructions for submission
Using your preferred code editor (e.g. VSCode), in a Python script called "CR3.py", write code to answer the following problem.
Problem
Consider the following ODE, describing the displacement of an oscillator (e.g. a mass attached to a spring) at time away from its
resting position:
where is the angular frequency of the oscillator, given as a fixed parameter. The initial conditions are given as
, the initial displacement,
, the initial velocity.
We seek to solve this equation numerically, using a finite difference method. We discretise time with a step size , and denote by the
approximation to computed at time step , that is .
We approximate the second derivative in the ODE with , to obtain the difference equation:
Rearranging this equation allows us to compute using values computed at the two previous time steps, and . We can initialise
and by discretising the initial conditions:
,
Then, we can compute , followed by , etc., for as many time steps as we desire.
Note that this method provides a "valid" solution as long as . This is called the stability condition.
Your task
Write a function "oscillator(w0, u0, v0, nmax, dt)" which takes 5 input arguments:
a positive number "w0", representing the parameter ,
two numbers "u0" and "v0", representing the initial conditions and respectively,
a positive integer "nmax" greater than or equal to 2, representing the total number of time steps,
a positive number "dt", representing the step size ,
and returns a Numpy vector "U" with a total of "nmax" elements, where the th element is the value of , the approximated solution for the
oscillator displacement at the th time step, computed using the method described above.
Dashboard / My courses / www.learn.ed__81855_1 / Code reviews / CR3
Computing and Numerics (2020-2021)[SEM2]
Setup phase Submission phase
Current phase
Submit your work
Open for submissions from
Monday, 8 March 2021,
2:00 PM (5 days ago)
Submissions deadline:
Monday, 15 March 2021,
12:00 PM (2 days left)
Assessment phase
Open for assessment from
Monday, 15 March 2021,
4:00 PM (2 days left)
Assessment deadline:
Monday, 22 March 2021,
12:00 PM (9 days left)
Grading evaluation phase Closed
Additionally, before computing the result, the function should check the value of and display a message if necessary:
if , display a message warning the user that the stability condition has been violated. Your message should include the maximum
value of "dt" allowed for the chosen value of "w0", to help your user choose a better step size next time.
if , display a message warning the user that the chosen step size is at the stability limit.
In either case, you should still compute and return the solution.
Testing
After the function definition, write a few tests to check that your function is working. Your first test should use the following values:
You can compare the computed solution to the exact solution, which is given by:
You could plot the exact and computed solutions on the same graph over time -- for valid step sizes (such that ), the two curves should
be close, but they will never be exactly overlapping; the peak values will often be where you see the largest error. For values of and close
to the stability condition (but still valid), you should see that the computed solution oscillates slightly faster than the exact solution. As we have
seen in many other situations, decreasing the step size should generally improve accuracy.
Try different values for the initial conditions and , and check that the first two values of your computed solution are set correctly. Try different
values for the frequency , increasing it should produce a faster-oscillating solution.
Make sure you check that the warning messages appear for appropriate values. Plot the computed solution for both problematic cases -- this is
what you should see:
when (and only when) , the amplitude of the oscillations in the computed solution should grow exponentially over time, and you
should see the first warning message.
when (and only when) , the amplitude of the oscillations in the computed solution should grow linearly over time, and you should
see the second warning message.
when (and only when) , the computed solution should oscillate without growing linearly or exponentially over time, and you should
not see any message.
You should include your test code in the script CR3.py, after the function definition. Make sure you label any plots you produce appropriately
and clearly.
Scope
This is for the more experienced programmers amongst you: remember that this is peer-assessed, and that Computing & Numerics is a course
designed for beginner programmers. Please try to stick to what we've seen in the course material so far, even if you feel confident in doing
something more advanced -- keep it simple.
You should not need to -- but if you absolutely want to use something we haven't seen in the course, then please keep it to a minimum, and make
sure you explain clearly what you are doing (and why) in the code comments, so that a student with little or no previous programming
experience can assess your work with confidence. If you don't follow these guidelines, and submit code which requires much more advanced
knowledge/experience with Python to fully understand than we have seen in the course so far, then your assessors will be able to penalise you
(see marking scheme below).
Submission
Upload your file "CR3.py" here when you are finished. Make sure you upload your file before Monday 15th March, 12pm (noon), otherwise you
won't be able to participate to the peer-assessment phase, and you will get a zero for the whole CR3 task!
Marking scheme
The marking scheme which you will use when assessing next week is given in the table below. Each criterion counts equally towards the grade,
and is assessed on a scale of 0 to 3.
Criteria 0 1 2 3
Δ𝑡
𝜔0Δ𝑡 > 2
𝜔0Δ𝑡 = 2
𝜔0 = 5, 𝑢0 = 0.2, 𝑣0 = 5, 𝑛m = 500, Δ𝑡 = 0.03. ax
𝑢(𝑡) = 𝑢0 cos(𝜔0 𝑡) + sin( 𝑡).
𝑣0
𝜔0 𝜔0
𝜔0Δ𝑡 < 2
Δ𝑡 𝜔0
Δ𝑡
𝑢0 𝑣0
𝜔0
𝜔0Δ𝑡 > 2
𝜔0Δ𝑡 = 2
𝜔0Δ𝑡 < 2
2021/3/13 CR3 (Submission phase)
https://moodle2.maths.ed.ac.uk/live2018/mod/workshop/view.php?id=3628 3/3
Was the file CR3.py submitted
correctly, and the code written as
instructed?
If you penalise here, indicate what
the problem was in the text box.
The file was in the
wrong format, which
made it difficult or
impossible to open.
The file was in the correct format,
but either didn't have the correct
name, or the code inside did not
follow the instructions (e.g. the
function was named differently, or
performed a completely different
task, or there was no function, or
there were no tests).
Everything was submitted in
the correct format and the
code followed the
specifications, but the code
was much too
complex/advanced compared
to what we have seen in the
course.
Everything was
submitted in the
correct format
and the code
followed the
specifications
(regardless of
whether it was
correct or not).
Is the code correct and without
bugs? Does the function
"oscillator()" produce the correct
results for any appropriate inputs?
If you can find any bugs or issues,
then you can indicate them in the
text box below to help the author fix
them. If you know that there is an
issue but you aren't sure why, then
indicate which test(s) look incorrect,
and give your best guess as to what
could be wrong.
(Use the test code provided in the
script by the student, as well as the
model answer and test code
provided by the instructors, to make
sure the code is fully functional.)
The code does not
work at all, there are a
lot of problems which
would take a long time
to find and fix.
There are a few bugs, so the code
works only for some input values,
but fails for many others (either
giving an error or returning the
wrong result).
There is a small number of
minor bugs or omissions, so
the code perhaps works for
most input values but fails for
a few special cases; or
perhaps the code doesn't work
but only because of a minor
issue which is trivial to fix.
The code works
correctly and
returns the
correct results for
all input values.
Was the function tested with an
appropriate range of different
inputs, to check if it worked?
(Whether or not the tests passed is
not relevant here.)
No tests were included
in the script.
Very few tests were performed,
not nearly enough to fully check
that the function worked.
A number of tests were
performed, which covered a
good number of possible
values, but perhaps some
important cases were missed.
A good number of
tests were
performed, which
covered all (or
almost all) of the
possible values
we could use with
this function.
Are the plots clear, easy to
understand, and appropriately
labelled?
The plots are extremely
messy, very hard to
read, and not clearly
The plots are perhaps too small or
squeezed, overlapping plots may
The plots are generally well
presented although a couple
The plots are very
well presented,
clearly and
Your submission
You have not submitted your work yet
Add submission
You are logged in as Yiwei Zong (Log out)
www.learn.ed__81855_1
Data retention summary
Get the mobile app
◀ CR2
Jump to...
Week 2 practice questions: Lists, loops, and functions ▶
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!