1. (a) Write a code to solve for the motion of the anharmonic oscillator described by the equation
dzx
W = -w2x3
Take to = 1 and initial conditions x = 1 and dx/dt = 0 and make a plot of the motion of the
oscillator from t = 0 to 20. Increase the amplitude to 10. You should observe that the oscillator
oscillates faster at higher amplitudes. (You can try lower amplitudes too if you like, which should
be slower.)
(b) Modify your program so that instead of plotting x against t, it plots dx/dt against x, i.e., the
velocity of the oscillator against its position. Such a plot is called a phase space plot. Make sure
you say pylab.axis(’equal’) to ensure the plot axes have the same length for the phase space plots.
(c) How does the behaviour in (a) and (b) differ (quantitatively) from a normal harmonic oscillator?
(Just run your code again after modifying the equation appropriately.) [30]
2. Consider the differential equation (called van der Pol oscillator):
x”(t) = -x – ¢-:(x2 – 1)x’(t),x(0) = 0.5, x’(0) = 0,
where e is a positive constant. As the value of 6 increases, this equation becomes increasingly stiff.
(a) Convert this equation to two first-order equations.
(b) Solve these equations using the Runge-Kutta method of 4th order provided in class with
e = 10, and [a, b] = [0, 1071:] and different choices of step-size: h = 0.02, 0.05 and 0.1. Plot
all solutions (one-by-one, in the above order), along with the solution obtained by using
the in-build scipy. integrate . odeint using linear axes, and (in a separate figure) plot the
absolute errors of all solutions using semi-log axes. What do you observe? Note that the in-
build method has a different interface to the function defining the equation(s) compared to
the supplied functions (the arguments are reversed). Result is also formatted differently,
check the help..
(c) Make a phase-space (coordinate vs. velocity) plot of the scipy . integrate . ode int solution
for e = 1, 4 and 10. Make sure you use a small enough value of the time interval h to get a
smooth, accurate phase space plot and again use p1 . axis ( ’ equal ’ ). [40]
3. Fourier filtering and smoothing
On Study Direct you’ll find a file called dow.txt. It contains the daily closing value for each
business day from late 2006 until the end of 2010 of the Dow Jones Industrial Average, which is a
measure of average prices of the largest companies of the US stock market.
Write a program to do the following:
12121.71
12136.44
12226.73
12221.93
12194.13
12283.85
12331.6
12309.25
12278.41
12307.48
12328.48
12315.58
12317.5
12416.76
12445.52
12441.27
12471.32
12463.87
12421.25
12343.21
12407.63
12510.57
12501.52
12463.15
12474.52
12480.69
12398.01
12423.49
12416.6
12442.16
12514.98
12556.08
12582.59
12577.15
12567.93
12565.53
12477.16
12533.8
12621.77
12502.56
12487.02
12490.78
12523.31
12621.69
12673.68
12653.49
12661.74
12666.31
12666.87
12637.63
12580.83
12552.55
12654.85
12741.86
12765.01
12767.57
12786.64
12738.41
12686.02
12647.48
12632.26
12216.24
12268.63
12234.34
12114.1
12050.41
12207.59
12192.45
12260.7
12276.32
12318.62
12075.96
12133.4
12159.68
12110.41
12226.17
12288.1
12447.52
12461.14
12481.01
12469.07
12397.29
12300.36
12348.75
12354.35
12382.3
12510.93
12530.05
12560.83
12569.14
12573.85
12484.62
12552.96
12612.13
12720.46
12773.04
12803.84
12808.63
12961.98
12919.4
12953.94
13089.89
13105.5
13120.94
13062.91
13136.14
13211.88
13241.38
13264.62
13312.97
13309.07
13362.87
13215.13
13326.22
13346.78
13383.84
13487.53
13476.72
13556.53
13542.88
13539.95
13525.65
13441.13
13507.28
13521.34
13633.08
13627.64
13668.11
13676.32
13595.46
13465.67
13266.73
13424.39
13424.96
13295.01
13482.35
13553.73
13639.48
13612.98
13635.42
13489.42
13545.84
13360.26
13352.05
13337.66
13427.73
13422.28
13408.62
13535.43
13577.3
13565.84
13611.68
13649.97
13501.7
13577.87
13861.73
13907.25
13950.98
13971.55
13918.22
14000.41
13851.08
13943.42
13716.95
13785.07
13473.57
13265.47
13358.31
13211.99
13362.37
13463.33
13181.91
13468.78
13504.3
13657.86
13270.68
13239.54
13236.53
13028.92
12861.47
12845.78
13079.08
13121.35
13090.86
13236.13
13235.88
13378.87
13322.13
13041.85
13289.29
13238.73
13357.74
13448.86
13305.47
13363.35
13113.38
13127.85
13308.39
13291.65
13424.88
13442.52
13403.42
13739.39
13815.56
13766.7
13820.19
13759.06
13778.65
13878.15
13912.94
13895.63
14087.55
14047.31
13968.05
13974.31
14066.01
14043.73
14164.53
14078.69
14015.12
14093.08
13984.8
13912.94
13892.54
13888.96
13522.02
13566.97
13676.23
13675.25
13671.92
13806.7
13870.26
13792.47
13930.01
13567.87
13595.1
13543.4
13660.94
13300.02
13266.29
13042.74
12987.55
13307.09
13231.01
13110.05
13176.79
12958.44
13010.14
12799.04
12980.88
12743.44
12958.44
13289.45
13311.73
13371.72
13314.57
13248.73
13444.96
13619.89
13625.58
13727.03
13432.77
13473.9
13517.96
13339.85
13167.2
13232.47
13207.27
13245.64
13450.65
13550.04
13551.69
13359.61
13365.87
13264.82
13043.96
13056.72
12800.18
12827.49
12589.07
12735.31
12853.09
12606.3
12778.15
12501.11
12466.16
12159.21
12099.3
11971.19
12270.17
12378.61
12207.17
12383.89
12480.3
12442.83
12650.36
12743.19
12635.16
12265.13
12200.1
12247
12182.13
12240.01
12373.41
12552.24
12376.98
12348.21
12337.22
12427.26
12284.3
12381.02
12570.22
12684.92
12694.28
12582.18
12266.39
12258.9
12213.8
12254.99
12040.39
11893.69
11740.15
12156.81
12110.24
12145.74
11951.09
11972.25
12392.66
12099.66
12361.32
12548.64
12532.6
12422.86
12302.46
12216.4
12262.89
12654.36
12608.92
12626.03
12609.42
12612.43
12576.44
12527.26
12581.98
12325.42
12302.06
12362.47
12619.27
12620.49
12849.36
12825.02
12720.23
12763.22
12848.95
12891.86
12871.75
12831.94
12820.13
13010
13058.2
12969.54
13020.83
12814.35
12866.78
12745.88
12876.05
12832.18
12898.38
12992.66
12986.8
13028.16
12828.68
12601.19
12625.62
12479.63
12548.35
12594.03
12646.22
12638.32
12503.82
12402.85
12390.48
12604.45
12209.81
12280.32
12289.76
12083.77
12141.58
12307.35
12269.08
12160.3
12029.06
12063.09
11842.69
11842.36
11807.43
11811.83
11453.42
11346.51
11350.01
11382.26
11215.51
11288.53
11231.96
11384.21
11147.44
11229.02
11100.54
11055.19
10962.54
11239.28
11446.66
11496.57
11467.34
11602.5
11632.38
11349.28
11370.69
11131.08
11397.56
11583.69
11378.02
11326.32
11284.15
11615.77
11656.07
11431.43
11734.32
11782.35
11642.47
11532.96
11615.93
11659.9
11479.39
11348.55
11417.43
11430.21
11628.06
11386.25
11412.87
11502.51
11715.18
11543.55
11516.92
11532.88
11188.23
11220.96
11510.74
11230.73
11268.92
11433.71
11421.99
10917.51
11059.02
10609.66
11019.69
11388.44
11015.69
10854.17
10825.17
11022.06
11143.13
10365.45
10850.66
10831.07
10482.85
10325.38
9955.5
9447.11
9258.1
8579.19
8451.19
9387.61
9310.99
8577.91
8979.26
8852.22
9265.43
9045.21
8519.21
8691.25
8378.95
8175.77
9065.12
8990.96
9180.69
9325.01
9319.83
9625.28
9139.27
8695.79
8943.81
8870.54
8693.96
8282.66
8835.25
8497.31
8273.58
8424.75
7997.28
7552.29
8046.42
8443.39
8479.47
8726.61
8829.04
8149.09
8419.09
8591.69
8376.24
8635.42
8934.18
8691.33
8761.42
8565.09
8629.68
8564.53
8924.14
8824.34
8604.99
8579.11
8519.69
8419.49
8468.48
8515.55
8483.93
8668.39
8776.39
9034.69
8952.89
9015.1
8769.7
8742.46
8599.18
8473.97
8448.56
8200.14
8212.49
8281.22
7949.09
8228.1
8122.8
8077.56
8116.03
8174.73
8375.45
8149.01
8000.86
7936.83
8078.36
7956.66
8063.07
8280.59
8270.87
7888.88
7939.53
7932.76
7850.41
7552.6
7555.63
7465.95
7365.67
7114.78
7350.94
7270.89
7182.08
7062.93
6763.29
6726.02
6875.84
6594.44
6626.94
6547.05
6926.49
6930.4
7170.06
7223.98
7216.97
7395.7
7486.58
7400.8
7278.38
7775.86
7660.21
7749.81
7924.56
7776.18
7522.02
7608.92
7761.6
7978.08
8017.59
7975.85
7789.56
7837.11
8083.38
8057.81
7920.18
8029.62
8125.43
8131.33
7841.73
7969.56
7886.57
7957.06
8076.29
8025
8016.95
8185.73
8168.12
8212.41
8426.74
8410.65
8512.28
8409.85
8574.65
8418.77
8469.11
8284.89
8331.32
8268.64
8504.08
8474.85
8422.04
8292.13
8277.32
8473.49
8300.02
8403.8
8500.33
8721.44
8740.87
8675.24
8750.24
8763.13
8764.49
8763.06
8739.02
8770.92
8799.26
8612.13
8504.67
8497.18
8555.6
8539.73
8339.01
8322.91
8299.86
8472.4
8438.39
8529.38
8447
8504.06
8280.74
8324.87
8163.6
8178.41
8183.17
8146.52
8331.68
8359.49
8616.21
8711.82
8743.94
8848.15
8915.94
8881.26
9069.29
9093.24
9108.51
9096.72
9070.72
9154.46
9171.61
9286.56
9320.19
9280.97
9256.26
9370.07
9337.95
9241.45
9361.61
9398.19
9321.4
9135.34
9217.94
9279.16
9350.05
9505.96
9509.28
9539.29
9543.52
9580.63
9544.2
9496.28
9310.6
9280.67
9344.61
9441.27
9497.34
9547.22
9627.48
9605.41
9626.8
9683.41
9791.71
9783.92
9820.2
9778.86
9829.87
9748.55
9707.44
9665.19
9789.36
9742.2
9712.28
9509.28
9487.67
9599.75
9731.25
9725.58
9786.87
9864.94
9885.8
9871.06
10015.86
10062.94
9995.91
10092.19
10041.48
9949.36
10081.31
9972.18
9867.96
9882.17
9762.69
9962.58
9712.73
9789.44
9771.91
9802.14
10005.96
10023.42
10226.94
10246.97
10291.26
10197.47
10270.47
10406.96
10437.42
10426.31
10332.44
10318.16
10450.95
10433.71
10464.4
10309.92
10344.84
10471.58
10452.68
10366.15
10388.9
10390.11
10285.97
10337.05
10405.83
10471.5
10501.05
10452
10441.12
10308.26
10328.89
10414.14
10464.93
10466.44
10520.1
10547.08
10545.41
10548.51
10428.05
10583.96
10572.02
10573.68
10606.86
10618.19
10663.99
10627.26
10680.77
10710.55
10609.65
10725.43
10603.15
10389.88
10172.98
10196.86
10194.29
10236.16
10120.46
10067.33
10185.53
10296.85
10270.55
10002.18
10012.23
9908.39
10058.64
10038.38
10144.19
10099.14
10268.81
10309.24
10392.9
10402.35
10383.38
10282.41
10374.16
10321.03
10325.26
10403.79
10405.98
10396.76
10444.14
10566.2
10552.52
10564.38
10567.33
10611.84
10624.69
10642.15
10685.98
10733.67
10779.17
10741.98
10785.89
10888.83
10836.15
10841.21
10850.36
10895.86
10907.42
10856.63
10927.07
10973.55
10969.99
10897.52
10927.07
10997.35
11005.97
11019.42
11123.11
11144.57
11018.66
11092.05
11117.06
11124.92
11134.29
11204.28
11205.03
10991.99
11045.27
11167.32
11008.61
11151.83
10926.77
10868.12
10520.32
10380.43
10785.14
10748.26
10896.91
10782.95
10620.16
10625.83
10510.95
10444.37
10068.01
10193.39
10066.57
10043.75
9974.45
10258.99
10136.63
10024.02
10249.54
10255.28
9931.97
9816.49
9939.98
9899.25
10172.53
10211.07
10190.89
10404.77
10409.46
10434.17
10450.64
10442.41
10293.52
10298.44
10152.8
10143.81
10138.52
9870.3
9774.02
9732.53
9686.48
9743.62
10018.28
10138.99
10198.03
10216.27
10363.02
10366.72
10359.31
10097.9
10154.43
10229.96
10120.53
10322.3
10424.62
10525.43
10537.69
10497.88
10467.16
10465.94
10674.38
10636.38
10680.43
10674.98
10653.56
10698.75
10644.25
10378.83
10319.95
10303.15
10302.01
10405.85
10415.54
10271.21
10213.62
10174.41
10040.45
10060.06
9985.81
10150.65
10009.73
10014.72
10269.47
10320.1
10447.93
10340.69
10387.01
10415.24
10462.77
10544.13
10526.49
10572.73
10594.83
10607.85
10753.62
10761.03
10739.31
10662.42
10860.26
10812.04
10858.14
10835.28
10788.05
10829.68
10751.27
10944.72
10967.65
10948.58
11006.48
11010.34
11020.4
11096.08
11096.92
11062.78
11143.69
10978.62
11107.97
11146.57
11132.56
11164.05
11169.46
11126.28
11113.95
11118.4
11124.62
11188.72
11215.13
11434.84
11444.08
11406.84
11346.75
11357.04
11283.1
11192.58
11201.97
11023.5
11007.88
11181.23
11203.55
11178.58
11036.37
11187.28
11092
11052.49
11006.02
11255.78
11362.41
11382.09
11362.19
11359.16
11372.48
11370.06
11410.32
11428.56
11476.54
11457.47
11499.25
11491.91
11478.13
PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET AN AMAZING DISCOUNT 🙂