首页 >
> 详细

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.

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-23:00
- 微信：codinghelp2

- Cs2461-10实验程序代做、代写java，C/C++，Python编程设 2021-03-02
- 代写program程序语言、代做python，C++课程程序、代写java编 2021-03-02
- Programming课程代做、代写c++程序语言、Algorithms编程 2021-03-02
- 代写csc1-Ua程序、代做java编程设计、Java实验编程代做 代做留学 2021-03-02
- 代做program编程语言、代写python程序、代做python设计编程 2021-03-02
- 代写data编程设计、代做python语言程序、Python课程编程代写 代 2021-03-02
- Cse 13S程序实验代做、代写c++编程、C/C++程序语言调试 代写留学 2021-03-02
- Mat136h5编程代做、C/C++程序调试、Python，Java编程设计 2021-03-01
- 代写ee425x实验编程、代做python，C++，Java程序设计 帮做c 2021-03-01
- Cscc11程序课程代做、代写python程序设计、Python编程调试 代 2021-03-01
- 代写program编程、Python语言程序调试、Python编程设计代写 2021-03-01
- 代做r语言编程|代做database|代做留学生p... 2021-03-01
- Data Structures代写、代做r编程课程、代做r程序实验 帮做ha 2021-03-01
- 代做data留学生编程、C++，Python语言代写、Java程序代做 代写 2021-03-01
- 代写aps 105编程实验、C/C++程序语言代做 代写r语言程序|代写py 2021-03-01
- Fre6831 Computational Finance 2021-02-28
- Sta141b Assignment 5 Interactive Visu... 2021-02-28
- Eecs2011a-F20 2021-02-28
- Comp-251 Final Asssessment 2021-02-28
- 代写cs1027课程程序、代做java编程语言、代写java留学生编程帮做h 2021-02-28