two matlab assignments
finite/1st Order ODES - annotated.pdf
Sensitivity: Internal
1st Order Ordinary Differential Equations (ODES)
Sensitivity: Internal
Disclaimer
We are merely looking to get an idea of the topic, we are not studying this rigorously! For a proper introduction there are plenty of online resources or textbooks.
You will also see these throughout the course in more detail.
We just want an idea so that we can compare a numerical method that we are going to learn.
Sensitivity: Internal
What is a 1st Order Ordinary Differential Equation (ODE) An equation involving the independent variable and the first derivative
𝑑𝑦
𝑑𝑥 + 2𝑦 = 𝑥 + 5
𝑑𝑦
𝑑𝑥 = 𝑥2
𝑑𝑦
𝑑𝑥 = 2𝑦
Sensitivity: Internal
Solutions to 1st Order Differential Equations
Find a function 𝑦(𝑥) which solves the following equations
𝑑𝑦
𝑑𝑥 = 𝑥2 (1)
Solution 𝑦(𝑥) = 𝑥3
3 + 𝐶 (2)
The derivative of the solution is 𝑑𝑦
𝑑𝑥 = 𝑥2
Why is it a solution, because it solves equation (1)
𝐿𝐻𝑆 = 𝑑𝑦
𝑑𝑥 = 𝑥2 = 𝑅𝐻𝑆
Sensitivity: Internal
Solutions to 1st Order Differential Equations
Find a function 𝑦 𝑥 which solves the following equations
𝑑𝑦
𝑑𝑥 = 2𝑦 (1)
Solution 𝑦 = 𝐴𝑒2𝑥 (2)
The derivative of the solution is 𝑑𝑦
𝑑𝑥 = 2𝐴𝑒𝑥
Why does a solution, because it solves equation (1)
𝐿𝐻𝑆 = 𝑑𝑦
𝑑𝑥 = 2𝐴𝑒𝑥 = 2𝑦 = 𝑅𝐻𝑆
Sensitivity: Internal
Worked Solution 1
𝑑𝑦
𝑑𝑥 = 𝑥2 (1)
Solve Complimentary 𝑑𝑦
𝑑𝑥 = 0
𝑦𝑐 = 𝐶1
Solve Particular
න𝑑𝑦 = න𝑥2𝑑𝑥
𝑦𝑝 = 𝑥3
3 + 𝐶2
Thus 𝑦 = 𝑦𝑐 + 𝑦𝑝
𝑦 = 𝑥3
3 + 𝐶1 + 𝐶2 +
𝑥3
3 + 𝐴
Check 𝑦 solves equations (1)
𝐿𝐻𝑆 = 𝑑𝑦
𝑑𝑥 = 𝑥2 = 𝑅𝐻𝑆
Sensitivity: Internal
Worked Solution 2
𝑑𝑦
𝑑𝑥 = 2𝑦 1
Sometime with extra information about the solution, known as an initial condition.
𝑦 0 = 2 (2)
Separate Variables
න 𝑑𝑦
𝑦 = න2𝑑𝑥
ln 𝑦 = 2𝑥 + 𝐶 𝑦 = 𝑒2𝑥+𝐶 = 𝐴𝑒2𝑥
To find 𝐴 use the initial condition 𝑦 0 = 2
𝑦 0 = 𝐴𝑒0 = 𝐴 = 2 ∴ 𝑦 = 2𝑒2𝑥
Check, we must check that our solution 𝑦 satisfies both equations (1) and (2)
𝐿𝐻𝑆 = 𝑑𝑦
𝑑𝑥 = 4𝑒2𝑥 = 2 2𝑒2𝑥 = 2𝑦 = 𝑅𝐻𝑆
And, 𝐿𝐻𝑆 = 𝑦 0 = 2𝑒2⋅0 = 2 = 𝑅𝐻𝑆
Sensitivity: Internal
Worked Solution 3
𝑑𝑦
𝑑𝑥 + 2𝑦 = 𝑥 + 5
Solve Complimentary
𝑑𝑦
𝑑𝑥 + 2𝑦 = 0
න 𝑑𝑦
𝑦 = න−2𝑑𝑥
ln 𝑦 = −2𝑥 + 𝐶 𝑦𝑐 = 𝐴𝑒
−2𝑥
Solve 𝑑𝑦
𝑑𝑥 + 2𝑦 = 𝑥 + 5
Assume 𝑦𝑝 = 𝑎𝑥 2 + 𝑏𝑥 + 𝑐
2𝑎𝑥 + 𝑏 + 2 𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 𝑥 + 5 2𝑎𝑥2 + 2𝑎 + 2𝑏 𝑥 + (𝑏 + 2𝑐) = 𝑥 + 5
Equate coefficients
2𝑎 + 2𝑏 = 1 = 1
2
𝑏 + 2𝑐 = 5,⇒ 𝑐 = 9
4
Thus 𝑦 = 𝑦𝑐 + 𝑦𝑝
𝑦 = 𝐴𝑒−2𝑥 + 𝑥
2 + 9
4
Check!
𝐿𝐻𝑆 = −2𝐴𝑒−2𝑥 + 1
2 + 2 𝐴𝑒−2𝑥 +
𝑥
2 + 9
4 = 𝑥 + 5 = 𝑅𝐻𝑆
Sensitivity: Internal
Springs
Imagine the movement of a spring, it goes up and down. If you plot this as time passes you get the following.
https://www.youtube.com/watch?v=P-Umre5Np_0
Sensitivity: Internal
Newtons Second Law
We are not studying physics, but this is important!
You can model a spring (undamped) using newtons second law
𝐹 = 𝑚𝑎
𝐹 = 𝑚 𝑑2𝑦
𝑑𝑡2
and hook’s force law 𝐹 = 𝑘𝑦
Equating we have,
−𝑘𝑦 = 𝑚 𝑑2𝑦
𝑑𝑡2 (1)
𝑑2𝑦
𝑑𝑡2 + 𝑘
𝑚 𝑦 = 0
Let 𝜔 = 𝑘
𝑚 𝑦 𝑡 = 𝑅𝑐𝑜𝑠(𝜔𝑡 + 𝛿)
Why? 𝑑𝑦
𝑑𝑡 = −𝜔𝑅𝑠𝑖𝑛 𝜔𝑡 + 𝛿
𝑑2𝑦
𝑑𝑡2 = −𝜔2𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿
Sub into (1)
𝐿𝐻𝑆 = −𝜔2𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿 + 𝑘
𝑚 𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿
= −𝜔2𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿 + 𝜔2𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿 = 𝑅𝐻𝑆
Sensitivity: Internal
The solution describes the springs movement in time!
𝑦 𝑡 = 𝑅𝑐𝑜𝑠(𝜔𝑡 + 𝛿)
𝑅 – amplitude
𝜔 - frequency
𝛿 - displacement
Interactive demo
https://www.desmos.com/calculator/dytbibashl
http://hyperphysics.phy-astr.gsu.edu/hbase/shm2.html
finite/1st Order ODES.pdf
Sensitivity: Internal
1st Order Ordinary Differential Equations (ODES)
Sensitivity: Internal
Disclaimer
We are merely looking to get an idea of the topic, we are not studying this rigorously! For a proper introduction there are plenty of online resources or textbooks.
You will also see these throughout the course in more detail.
We just want an idea so that we can compare a numerical method that we are going to learn.
Sensitivity: Internal
What is a 1st Order Ordinary Differential Equation (ODE) An equation involving the independent variable and the first derivative
𝑑𝑦
𝑑𝑥 = 𝑓 𝑥
e.g. 𝑑𝑦
𝑑𝑥 = 𝑥2
𝑑𝑦
𝑑𝑥 = 𝑓(𝑥,𝑦)
𝑑𝑦
𝑑𝑥 + 2𝑦 = 𝑥 + 5
𝑑𝑦
𝑑𝑥 = 2𝑦
Note that here 𝑓 𝑥,𝑦 = 0𝑥 + 2𝑦
Sensitivity: Internal
Solutions to 1st Order Differential Equations
Find a function 𝑦(𝑥) which solves the following equation
𝑑𝑦
𝑑𝑥 = 𝑥2 (1)
Solution 𝑦(𝑥) = 𝑥3
3 + 𝐶 (2)
The derivative of the solution is 𝑑𝑦
𝑑𝑥 = 𝑥2
Why is it a solution, because it solves equation (1)
𝐿𝐻𝑆 = 𝑑𝑦
𝑑𝑥 = 𝑥2 = 𝑅𝐻𝑆
Sensitivity: Internal
Solutions to 1st Order Differential Equations
Find a function 𝑦 𝑥 which solves the following equation
𝑑𝑦
𝑑𝑥 = 2𝑦 (1)
Solution 𝑦 = 𝐴𝑒2𝑥 (2)
The derivative of the solution is 𝑑𝑦
𝑑𝑥 = 2𝐴𝑒𝑥
Why does a solution, because it solves equation (1)
𝐿𝐻𝑆 = 𝑑𝑦
𝑑𝑥 = 2𝐴𝑒𝑥 = 2𝑦 = 𝑅𝐻𝑆
Sensitivity: Internal
Worked Solution 1
𝑑𝑦
𝑑𝑥 = 𝑥2 (1)
Solve Complimentary 𝑑𝑦
𝑑𝑥 = 0
𝑦𝑐 = 𝐶1
Solve Particular
න𝑑𝑦 = න𝑥2𝑑𝑥
𝑦𝑝 = 𝑥3
3 + 𝐶2
Thus 𝑦 = 𝑦𝑐 + 𝑦𝑝
𝑦 = 𝑥3
3 + 𝐶1 + 𝐶2 +
𝑥3
3 + 𝐴
Check 𝑦 solves equations (1)
𝐿𝐻𝑆 = 𝑑𝑦
𝑑𝑥 = 𝑥2 = 𝑅𝐻𝑆
Sensitivity: Internal
Worked Solution 2
𝑑𝑦
𝑑𝑥 = 2𝑦 1
Sometime with extra information about the solution, known as an initial condition.
𝑦 0 = 2 (2)
Separate Variables
න 𝑑𝑦
𝑦 = න2𝑑𝑥
ln 𝑦 = 2𝑥 + 𝐶 𝑦 = 𝑒2𝑥+𝐶 = 𝐴𝑒2𝑥
To find 𝐴 use the initial condition 𝑦 0 = 2
𝑦 0 = 𝐴𝑒0 = 𝐴 = 2 ∴ 𝑦 = 2𝑒2𝑥
Check, we must check that our solution 𝑦 satisfies both equations (1) and (2)
𝐿𝐻𝑆 = 𝑑𝑦
𝑑𝑥 = 4𝑒2𝑥 = 2 2𝑒2𝑥 = 2𝑦 = 𝑅𝐻𝑆
And, 𝐿𝐻𝑆 = 𝑦 0 = 2𝑒2⋅0 = 2 = 𝑅𝐻𝑆
Sensitivity: Internal
Worked Solution 3
𝑑𝑦
𝑑𝑥 + 2𝑦 = 𝑥 + 5
Solve Complimentary
𝑑𝑦
𝑑𝑥 + 2𝑦 = 0
න 𝑑𝑦
𝑦 = න−2𝑑𝑥
ln 𝑦 = −2𝑥 + 𝐶 𝑦𝑐 = 𝐴𝑒
−2𝑥
Solve 𝑑𝑦
𝑑𝑥 + 2𝑦 = 𝑥 + 5
Assume 𝑦𝑝 = 𝑎𝑥 2 + 𝑏𝑥 + 𝑐
2𝑎𝑥 + 𝑏 + 2 𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 𝑥 + 5 2𝑎𝑥2 + 2𝑎 + 2𝑏 𝑥 + (𝑏 + 2𝑐) = 𝑥 + 5
Equate coefficients
2𝑎 + 2𝑏 = 1 = 1
2
𝑏 + 2𝑐 = 5,⇒ 𝑐 = 9
4
Thus 𝑦 = 𝑦𝑐 + 𝑦𝑝
𝑦 = 𝐴𝑒−2𝑥 + 𝑥
2 + 9
4
Check!
𝐿𝐻𝑆 = −2𝐴𝑒−2𝑥 + 1
2 + 2 𝐴𝑒−2𝑥 +
𝑥
2 + 9
4 = 𝑥 + 5 = 𝑅𝐻𝑆
Sensitivity: Internal
Springs
Imagine the movement of a spring, it goes up and down. If you plot this as time passes you get the following.
https://www.youtube.com/watch?v=P-Umre5Np_0
Sensitivity: Internal
Newtons Second Law
We are not studying physics, but this is important!
You can model a spring (undamped) using newtons second law
𝐹 = 𝑚𝑎
𝐹 = 𝑚 𝑑2𝑦
𝑑𝑡2
and hook’s force law 𝐹 = 𝑘𝑦
Equating we have,
−𝑘𝑦 = 𝑚 𝑑2𝑦
𝑑𝑡2 (1)
𝑑2𝑦
𝑑𝑡2 + 𝑘
𝑚 𝑦 = 0
Let 𝜔 = 𝑘
𝑚 𝑦 𝑡 = 𝑅𝑐𝑜𝑠(𝜔𝑡 + 𝛿)
Why? 𝑑𝑦
𝑑𝑡 = −𝜔𝑅𝑠𝑖𝑛 𝜔𝑡 + 𝛿
𝑑2𝑦
𝑑𝑡2 = −𝜔2𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿
Sub into (1)
𝐿𝐻𝑆 = −𝜔2𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿 + 𝑘
𝑚 𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿
= −𝜔2𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿 + 𝜔2𝑅𝑐𝑜𝑠 𝜔𝑡 + 𝛿 = 𝑅𝐻𝑆
Sensitivity: Internal
The solution describes the springs movement in time!
𝑦 𝑡 = 𝑅𝑐𝑜𝑠(𝜔𝑡 + 𝛿)
𝑅 – amplitude
𝜔 - frequency
𝛿 - displacement
Interactive demo
https://www.desmos.com/calculator/dytbibashl
http://hyperphysics.phy-astr.gsu.edu/hbase/shm2.html
finite/excel_finite_differences - example 1 (2).xlsx
Sheet1
| k | x_k | y_k | y | Error | h | 0.1 | |
| 1 | 0 | 2 | 1 | 1 | |||
| 2 | 0.1 | 2.4 | 1.2214027582 | 1.1785972418 | |||
| 3 | 0.2 | 2.88 | 1.4918246976 | 1.3881753024 | |||
| 4 | 0.3 | 3.456 | 1.8221188004 | 1.6338811996 | |||
| 5 | 0.4 | 4.1472 | 2.2255409285 | 1.9216590715 | |||
| 6 | 0.5 | 4.97664 | 2.7182818285 | 2.2583581715 | |||
| 7 | 0.6 | 5.971968 | 3.3201169227 | 2.6518510773 | |||
| 8 | 0.7 | 7.1663616 | 4.0551999668 | 3.1111616332 | |||
| 9 | 0.8 | 8.59963392 | 4.9530324244 | 3.6466014956 | |||
| 10 | 0.9 | 10.319560704 | 6.0496474644 | 4.2699132396 | |||
| 11 | 1 | 12.3834728448 | 7.3890560989 | 4.9944167459 | |||
| 12 | 1.1 | 14.8601674138 | 9.0250134994 | 5.8351539143 | |||
| 13 | 1.2 | 17.8322008965 | 11.0231763806 | 6.8090245159 | |||
| 14 | 1.3 | 21.3986410758 | 13.463738035 | 7.9349030408 | |||
| 15 | 1.4 | 25.678369291 | 16.4446467711 | 9.2337225199 | |||
| 16 | 1.5 | 30.8140431492 | 20.0855369232 | 10.728506226 | |||
| 17 | 1.6 | 36.976851779 | 24.5325301971 | 12.4443215819 | |||
| 18 | 1.7 | 44.3722221348 | 29.9641000474 | 14.4081220874 | |||
| 19 | 1.8 | 53.2466665618 | 36.5982344437 | 16.6484321181 | |||
| 20 | 1.9 | 63.8959998741 | 44.7011844933 | 19.1948153808 | |||
| 21 | 2 | 76.6751998489 | 54.5981500331 | 22.0770498158 | |||
| 22 | 2.1 | 92.0102398187 | 66.6863310409 | 25.3239087778 | |||
| 23 | 2.2 | 110.4122877825 | 81.450868665 | 28.9614191175 | |||
| 24 | 2.3 | 132.494745339 | 99.4843156419 | 33.0104296971 | |||
| 25 | 2.4 | 158.9936944068 | 121.5104175187 | 37.483276888 | |||
| 26 | 2.5 | 190.7924332881 | 148.4131591026 | 42.3792741856 | |||
| 27 | 2.6 | 228.9509199458 | 181.2722418752 | 47.6786780706 | |||
| 28 | 2.7 | 274.7411039349 | 221.4064162042 | 53.3346877307 | |||
| 29 | 2.8 | 329.6893247219 | 270.4264074262 | 59.2629172957 | |||
| 30 | 2.9 | 395.6271896663 | 330.2995599096 | 65.3276297566 | |||
| 31 | 3 | 474.7526275995 | 403.4287934927 | 71.3238341068 | |||
| 32 | 3.1 | 569.7031531194 | 492.7490410933 | 76.9541120262 | |||
| 33 | 3.2 | 683.6437837433 | 601.8450378721 | 81.7987458713 | |||
| 34 | 3.3 | 820.372540492 | 735.095189242 | 85.27735125 | |||
| 35 | 3.4 | 984.4470485904 | 897.8472916504 | 86.59975694 | |||
| 36 | 3.5 | 1181.3364583085 | 1096.6331584285 | 84.70329988 | |||
| 37 | 3.6 | 1417.6037499702 | 1339.4307643944 | 78.1729855758 | |||
| 38 | 3.7 | 1701.1244999642 | 1635.9844299959 | 65.1400699683 | |||
| 39 | 3.8 | 2041.3493999571 | 1998.1958951041 | 43.1535048529 | |||
| 40 | 3.9 | 2449.6192799485 | 2440.6019776245 | 9.017302324 | |||
| 41 | 4 | 2939.5431359382 | 2980.9579870417 | -41.4148511036 | |||
| 42 | 4.1 | 3527.4517631258 | 3640.9503073324 | -113.4985442066 | |||
| 43 | 4.2 | 4232.942115751 | 4447.0667476999 | -214.1246319489 | |||
| 44 | 4.3 | 5079.5305389012 | 5431.659591363 | -352.1290524618 | |||
| 45 | 4.4 | 6095.4366466814 | 6634.2440062779 | -538.8073595965 | |||
| 46 | 4.5 | 7314.5239760177 | 8103.0839275754 | -788.5599515577 | |||
| 47 | 4.6 | 8777.4287712212 | 9897.1290587439 | -1119.7002875227 | |||
| 48 | 4.7 | 10532.9145254654 | 12088.380730217 | -1555.4662047515 | |||
| 49 | 4.8 | 12639.4974305585 | 14764.7815655772 | -2125.2841350187 | |||
| 50 | 4.9 | 15167.3969166702 | 18033.7449278285 | -2866.3480111582 | |||
| 51 | 5 | 18200.8763000043 | 22026.4657948066 | -3825.5894948024 | |||
| 52 | 5.1 | 21841.0515600051 | 26903.1860742974 | -5062.1345142923 |
y_k 2 2.4 2.88 3.456 4.1471999999999998 4.9766399999999997 5.9719679999999995 7.1663615999999992 8.5996339199999987 10.319560703999999 12.383472844799998 14.860167413759998 17.832200896511996 21.398641075814393 25.678369290977269 30.814043149172722 36.976851779007262 44.372222134808716 53.246666561770461 63.895999874124549 76.675199848949461 92.01023981873935 110.41228778248721 132.49474533898464 158.99369440678157 190.79243328813789 228.95091994576546 274.74110393491856 329.68932472190227 395.62718966628273 474.75262759953927 569.70315311944705 683.64378374333648 820.37254049200374 984.44704859040439 1181.3364583084851 1417.6037499701822 1701.1244999642186 2041.3493999570621 2449.6192799484743 2939.5431359381691 3527.4517631258027 4232.9421157509632 5079.5305389011555 6095.4366466813863 7314.5239 760176637 8777.4287712211953 10532.914525465434 12639.49743055852 15167.396916670223 18200.876300004267 21841.051560005119 y 1 1.2214027581601699 1.4918246976412703 1.8221188003905091 2.2255409284924679 2.7182818284590451 3.3201169227365472 4.0551999668446745 4.953032424395114 6.0496474644129448 7.3890560989306486 9.0250134994341185 11.023176380641601 13.463738035001692 16.444646771097055 20.085536923187675 24.532530197109363 29.964100047397036 36.598234443678024 44.701184493300872 54.598150033144286 66.686331040925211 81.450868664968212 99.484315641933946 121.51041751873508 148.41315910257686 181.27224187515154 221.40641620418756 270.42640742615328 330.29955990964947 403.42879349273619 492.74904109325763 601.84503787208382 735.09518924197528 897.84729165042074 1096.6331584284626 1339.4307643944228 1635.9844299959329 1998.1958951041261 2440.6019776245093 2980.9579870417388 3640.9503073323649 4447.0667476998651 5431.6595913629881 6634.2440062778896 8103.0839275753842 9897.1290587439089 12088.380730216968 14764.781565577241 18033.744927828458 22026.465794806638 26903.186074297446
Error 1 1.1785972418398301 1.3881753023587295 1.6338811996094909 1.9216590715075319 2.2583581715409546 2.6518510772634523 3.1111616331553247 3.6466014956048847 4.269913239587054 4.9944167458693496 5.835153914325879 6.8090245158703944 7.934903040812701 9.2337225198802138 10.728506225985047 12.444321581897899 14.40812208741168 16.648432118092437 19.194815380823677 22.077049815805175 25.32390877781414 28.961419117519 33.010429697050697 37.48327688804649 42.37927418556103 47.678678070613927 53.334687730730991 59.262917295748991 65.327629756633257 71.323834106803076 76.954112026189421 81.798745871252663 85.27735125002846 86.599756939983649 84.703299880022541 78.172985575759412 65.140069968285616 43.153504852936067 9.017302323964941 -41.414851103569617 -113.4985442065622 -214.12463194890188 -352.12905246183254 -538.80735959650337 -788.55995155772052 -1119.7002875227136 -1555.466204751534 -2125.2841350187209 -2866.3480111582357 -3825.5894948023706 -5062.1345142923274
y_k 2 2.4 2.88 3.456 4.1471999999999998 4.9766399999999997 5.9719679999999995 7.1663615999999992 8.5996339199999987 10.319560703999999 12.383472844799998 14.860167413759998
finite/excel_finite_differences - example 2.xlsx
Sheet1
| k | x_k | y_k | Analytical | Error | h | 0.1 | |
| 1 | 0 | 2 | 2 | 0 | |||
| 2 | 0.1 | 2.4 | 2.4481562059 | -0.0481562059 | |||
| 3 | 0.2 | 2.88 | 3.0066055697 | -0.1266055697 | |||
| 4 | 0.3 | 3.456 | 3.6997673009 | -0.2437673009 | |||
| 5 | 0.4 | 4.1472 | 4.5574670891 | -0.4102670891 | |||
| 6 | 0.5 | 4.97664 | 5.616134114 | -0.639494114 | |||
| 7 | 0.6 | 5.971968 | 6.9202630762 | -0.9482950762 | |||
| 8 | 0.7 | 7.1663616 | 8.5241999254 | -1.3578383254 | |||
| 9 | 0.8 | 8.59963392 | 10.4943229549 | -1.8946890349 | |||
| 10 | 0.9 | 10.319560704 | 12.9117067949 | -2.5921460909 | |||
| 11 | 1 | 12.3834728448 | 15.8753762226 | -3.4919033778 | |||
| 12 | 1.1 | 14.8601674138 | 19.5062803737 | -4.64611296 | |||
| 13 | 1.2 | 17.8322008965 | 23.9521468564 | -6.1199459599 | |||
| 14 | 1.3 | 21.3986410758 | 29.3934105788 | -7.9947695029 | |||
| 15 | 1.4 | 25.678369291 | 36.050455235 | -10.372085944 | |||
| 16 | 1.5 | 30.8140431492 | 44.1924580772 | -13.378414928 | |||
| 17 | 1.6 | 36.976851779 | 54.1481929435 | -17.1713411645 | |||
| 18 | 1.7 | 44.3722221348 | 66.3192251066 | -21.9470029718 | |||
| 19 | 1.8 | 53.2466665618 | 81.1960274983 | -27.9493609365 | |||
| 20 | 1.9 | 63.8959998741 | 99.3776651099 | -35.4816652358 | |||
| 21 | 2 | 76.6751998489 | 121.5958375746 | -44.9206377256 | |||
| 22 | 2.1 | 92.0102398187 | 148.7442448421 | -56.7340050233 | |||
| 23 | 2.2 | 110.4122877825 | 181.9144544962 | -71.5021667137 | |||
| 24 | 2.3 | 132.494745339 | 222.4397101944 | -89.9449648554 | |||
| 25 | 2.4 | 158.9936944068 | 271.9484394172 | -112.9547450104 | |||
| 26 | 2.5 | 190.7924332881 | 332.4296079808 | -141.6371746927 | |||
| 27 | 2.6 | 228.9509199458 | 406.3125442191 | -177.3616242733 | |||
| 28 | 2.7 | 274.7411039349 | 496.5644364594 | -221.8233325245 | |||
| 29 | 2.8 | 329.6893247219 | 606.8094167088 | -277.1200919869 | |||
| 30 | 2.9 | 395.6271896663 | 741.4740097967 | -345.8468201304 | |||
| 31 | 3 | 474.7526275995 | 905.9647853587 | -431.2121577591 | |||
| 32 | 3.1 | 569.7031531194 | 1106.8853424598 | -537.1821893404 | |||
| 33 | 3.2 | 683.6437837433 | 1352.3013352122 | -668.6575514689 | |||
| 34 | 3.3 | 820.372540492 | 1652.0641757944 | -831.6916353024 | |||
| 35 | 3.4 | 984.4470485904 | 2018.2064062135 | -1033.759357623 | |||
| 36 | 3.5 | 1181.3364583085 | 2465.424606464 | -1284.0881481556 | |||
| 37 | 3.6 | 1417.6037499702 | 3011.6692198874 | -1594.0654699173 | |||
| 38 | 3.7 | 1701.1244999642 | 3678.8649674909 | -1977.7404675266 | |||
| 39 | 3.8 | 2041.3493999571 | 4493.7907639843 | -2452.4413640272 | |||
| 40 | 3.9 | 2449.6192799485 | 5489.1544496551 | -3039.5351697067 | |||
| 41 | 4 | 2939.5431359382 | 6704.9054708439 | -3765.3623349057 | |||
| 42 | 4.1 | 3527.4517631258 | 8189.8381914978 | -4662.386428372 | |||
| 43 | 4.2 | 4232.942115751 | 10003.5501823247 | -5770.6080665737 | |||
| 44 | 4.3 | 5079.5305389012 | 12218.8340805667 | -7139.3035416656 | |||
| 45 | 4.4 | 6095.4366466814 | 14924.5990141253 | -8829.1623674439 | |||
| 46 | 4.5 | 7314.5239760177 | 18229.4388370446 | -10914.914861027 | |||
| 47 | 4.6 | 8777.4287712212 | 22265.9903821738 | -13488.5616109526 | |||
| 48 | 4.7 | 10532.9145254654 | 27196.2566429882 | -16663.3421175227 | |||
| 49 | 4.8 | 12639.4974305585 | 33218.1085225488 | -20578.6110919903 | |||
| 50 | 4.9 | 15167.3969166702 | 40573.226087614 | -25405.8291709438 | |||
| 51 | 5 | 18200.8763000043 | 49556.7980383149 | -31355.9217383107 | |||
| 52 | 5.1 | 21841.0515600051 | 60529.3686671692 | -38688.3171071641 |
Error 0 -4.8156205860382606E-2 -0.1266055696928583 -0.24376730087864562 -0.41026708910805265 -0.63949411403285161 -0.94829507615723152 -1.3578383254005191 -1.8946890348890069 -2.592146090929127 -3.4919033777939621 -4.6461129599667697 -6.1199459599316057 -7.9947695029394161 -10.372085943991099 -13.378414927999547 -17.171341164488808 -21.947002971834614 -27.949360936505094 -35.481665235802403 -44.920637725625184 -56.734005023342363 -71.502166713691267 -89.94496485536672 -112.95474501037239 -141.63717469266004 -177.3616242733255 -221.82333252450343 -277.12009198694261 -345.84682013042851 -431.21215775911713 -537.18218934038259 -668.65755146885215 -831.69163530244055 -1033.7593576230422 -1284.0881481555559 -1594.065469917269 -1977.7404675266307 -2452.4413640272223 -3039.5351697066717 -3765.3623349057434 -4662.3864283720177 -5770.6080665737327 -7139.3035416655675 -8829.1623674438652 -10914.914861026951 -13488.561610952602 -16663.342117522749 -20578.611091990271 -25405.829170943813 -31355.921738310666 -38688.317107164126
y_k 2 2.4 2.88 3.456 4.1471999999999998 4.9766399999999997 5.9719679999999995 7.1663615999999992 8.5996339199999987 10.319560703999999 12.383472844799998 14.860167413759998
finite/Finite Differences - annotated.pdf
Sensitivity: Internal
Finite Differences
Sensitivity: Internal
Rationale
There are differential equations we just can’t solve.
𝑑𝑦
𝑑𝑥 + sin 𝑥 𝑦 + 3𝑦 + 𝑥𝑦 = 𝑥 + 5
Sensitivity: Internal
Starter Problem
We will find a numerical answer to the following 𝑑𝑦
𝑑𝑥 = 2𝑦 1
𝑦 0 = 2 (2)
Sensitivity: Internal
Approximations via Calculus
We can make use of some basic calculus definitions
𝑑𝑦
𝑑𝑥 = lim
ℎ→0
𝑓 𝑥 + ℎ − 𝑓(𝑥)
ℎ
Sensitivity: Internal
Difference Quotient
We can make use of some basic calculus definitions
𝑑𝑦
𝑑𝑥 = lim
ℎ→0
𝑓 𝑥+ℎ −𝑓(𝑥)
ℎ
Therefore we can approximate 𝑑𝑦
𝑑𝑥 ≈
𝑓 𝑥+ℎ −𝑓(𝑥)
ℎ
𝑥 𝑥 + ℎ
𝑓(𝑥)
𝑓(𝑥 + ℎ)
Sensitivity: Internal
Notation
Let ℎ be a fixed constant
𝑑𝑦
𝑑𝑥 ≈
𝑓 𝑥𝑘+1 −𝑓(𝑥𝑘)
ℎ
OR we use 𝑦𝑘+1 and 𝑦𝑘
𝑑𝑦
𝑑𝑥 ≈
𝑦𝑘+1− 𝑦𝑘
ℎ
𝑥1 𝑥2
𝑦𝑘 = 𝑓(𝑥𝑘)
𝑦𝑘+1 = 𝑓 𝑥𝑘+1
𝑥𝑛𝑥𝑘 𝑥𝑘+1
Sensitivity: Internal
Forward Difference Scheme
𝑑𝑦
𝑑𝑥 ≈ 𝑦𝑘+1 − 𝑦𝑘
ℎ
We can use this to set up a scheme for 𝑑𝑦
𝑑𝑥 = 2𝑦
𝑦𝑘+1 − 𝑦𝑘 ℎ
= 2𝑦𝑘
Rearrange so that 𝑦𝑘+1 is the subject 𝑦𝑘+1 = 2ℎ𝑦𝑘 + 𝑦𝑘
𝑦𝑘+1 = 1 + 2ℎ 𝑦𝑘
Sensitivity: Internal
How do we start???
𝑦𝑘+1 = 1 + 2ℎ 𝑦𝑘
Let 𝑘 = 0 𝑦1 = 1 + 2ℎ 𝑦0 (3)
To get 𝑦1 we need 𝑦0 This comes from the initial condition 𝑦 0 = 2
𝑦0 = 2
From (3) 𝑦1 = 1 + 2ℎ ⋅ 2
e.g. if ℎ = 0.1 𝑦1 = 1 + 2 ⋅ 0.1 ⋅ 2 = 2.4
Sensitivity: Internal
Results
𝑦𝑘+1 = 1 + 2ℎ 𝑦𝑘 𝑦0 = 2
Sensitivity: Internal
What is a 1st Order Differential Equation
𝑑𝑦
𝑑𝑥 ≈ 𝑦𝑘+1 − 𝑦𝑘
ℎ
We can use this to set up a scheme for 𝑑𝑦
𝑑𝑥 = 2𝑦 + 𝑥
𝑦 0 = 2
𝑦𝑘+1 − 𝑦𝑘 ℎ
= 2𝑦𝑘 + 𝑥𝑘
Rearrange so that 𝑦𝑘+1 is the subject 𝑦𝑘+1 − 𝑦𝑘 = ℎ(2𝑦𝑘 + 𝑥𝑘)
𝑦𝑘+1 = 1 + 2ℎ 𝑦𝑘 + ℎ𝑥𝑘
finite/Finite Differences.pdf
Sensitivity: Internal
Finite Differences
Sensitivity: Internal
Rationale
There are differential equations we just can’t solve.
𝑑𝑦
𝑑𝑥 + sin 𝑥 𝑦 + 3𝑦 + 𝑥𝑦 = 𝑥 + 5
Sensitivity: Internal
Starter Problem
We will find a numerical answer to the following 𝑑𝑦
𝑑𝑥 = 2𝑦 1
𝑦 0 = 2 (2)
Sensitivity: Internal
Approximations via Calculus
We can make use of some basic calculus definitions
𝑑𝑦
𝑑𝑥 = lim
ℎ→0
𝑓 𝑥 + ℎ − 𝑓(𝑥)
ℎ
Sensitivity: Internal
Difference Quotient
We can make use of some basic calculus definitions
𝑑𝑦
𝑑𝑥 = lim
ℎ→0
𝑓 𝑥+ℎ −𝑓(𝑥)
ℎ
Therefore we can approximate 𝑑𝑦
𝑑𝑥 ≈
𝑓 𝑥+ℎ −𝑓(𝑥)
ℎ
𝑥 𝑥 + ℎ
𝑓(𝑥)
𝑓(𝑥 + ℎ)
Sensitivity: Internal
Notation
Let ℎ be a fixed constant
𝑑𝑦
𝑑𝑥 ≈
𝑓 𝑥𝑘+1 −𝑓(𝑥𝑘)
ℎ
OR we use 𝑦𝑘+1 and 𝑦𝑘
𝑑𝑦
𝑑𝑥 ≈
𝑦𝑘+1− 𝑦𝑘
ℎ
𝑥1 𝑥2
𝑦𝑘 = 𝑓(𝑥𝑘)
𝑦𝑘+1 = 𝑓 𝑥𝑘+1
𝑥𝑛𝑥𝑘 𝑥𝑘+1
Sensitivity: Internal
Forward Difference Scheme
𝑑𝑦
𝑑𝑥 ≈ 𝑦𝑘+1 − 𝑦𝑘
ℎ
We can use this to set up a scheme for 𝑑𝑦
𝑑𝑥 = 2𝑦
𝑦𝑘+1 − 𝑦𝑘 ℎ
= 2𝑦𝑘
Rearrange so that 𝑦𝑘+1 is the subject 𝑦𝑘+1 = 2ℎ𝑦𝑘 + 𝑦𝑘
𝑦𝑘+1 = 1 + 2ℎ 𝑦𝑘
Sensitivity: Internal
How do we start???
𝑦𝑘+1 = 1 + 2ℎ 𝑦𝑘
Let 𝑘 = 0 𝑦1 = 1 + 2ℎ 𝑦0 (3)
To get 𝑦1 we need 𝑦0 This comes from the initial condition 𝑦 0 = 2
𝑦0 = 2
From (3) 𝑦1 = 1 + 2ℎ ⋅ 2
e.g. if ℎ = 0.1 𝑦1 = 1 + 2 ⋅ 0.1 ⋅ 2 = 2.4
Sensitivity: Internal
Results
𝑦𝑘+1 = 1 + 2ℎ 𝑦𝑘 𝑦0 = 2
Sensitivity: Internal
What is a 1st Order Differential Equation
𝑑𝑦
𝑑𝑥 ≈ 𝑦𝑘+1 − 𝑦𝑘
ℎ
We can use this to set up a scheme for 𝑑𝑦
𝑑𝑥 = 2𝑦 + 𝑥
𝑦 0 = 2
𝑦𝑘+1 − 𝑦𝑘 ℎ
= 2𝑦𝑘 + 𝑥𝑘
Rearrange so that 𝑦𝑘+1 is the subject 𝑦𝑘+1 − 𝑦𝑘 = ℎ(2𝑦𝑘 + 𝑥𝑘)
𝑦𝑘+1 = 1 + 2ℎ 𝑦𝑘 + ℎ𝑥𝑘
finite/Forward Differences Notes with Example.pdf
Solve the following differential equation with initial condition using the forward differences scheme.
𝑑𝑦
𝑑𝑥 = 2𝑦 + 𝑥2, 𝑦(0) = 5
Equally discretised the space that you wish to approximate over. Here we are looking to
approximate the red curve over the space [0,2]
Here we have “chunked” the space into equal parts by a step size of ℎ = 0.2
𝑥0 = 0
𝑥1 = 0.2
⋮
𝑥𝑛−1 = 1.9
𝑥𝑛 = 2
We can approximate the first derivative by,
𝑑𝑦
𝑑𝑥 ≈
𝑦𝑘+1 − 𝑦𝑘 ℎ
Where,
𝑥 = 𝑥𝑘
𝑦 = 𝑦𝑘
and use this to create an iterative method to solve our differential equation.
e.g. for the following
𝑑𝑦
𝑑𝑥 = 2𝑦 + 𝑥2, 𝑦(0) = 5
𝑦𝑘+1 − 𝑦𝑘 ℎ
= 2𝑦𝑘 + 𝑥𝑘 2
𝑦𝑘+1 = 𝑦𝑘 + 2ℎ𝑦𝑘 + ℎ𝑥𝑘 2
𝑦𝑘+1 = (1 + 2ℎ)𝑦𝑘 + ℎ𝑥𝑘 2
Then for a step size of ℎ = 0.2 we have
and,
𝑦𝑘+1 = (1 + 2 ⋅ 0.2)𝑦𝑘 + 0.2𝑥𝑘 2
𝑦𝑘+1 = 1.4𝑦𝑘 + 0.2𝑥𝑘 2
e.g.
𝑘 = 0
We require 𝑥0 and 𝑦0, which we can get from our initial condition 𝑦(0) = 5, giving,
𝑥0 = 0, 𝑦0 = 5
Thus
𝑦1 = 1.4𝑦0 + 0.2𝑥0 2 = 1.4 ⋅ 5 = 7
𝑘 = 1,
𝑥1 = 𝑥0 + ℎ = 0 + 0.2 = 0.2, 𝑦1 = 7
𝑦2 = 1.4𝑦1 + 0.2𝑥1 2 = 1.4 ⋅ 7 + 0.2 ⋅ 0.22 = 9.808
etc….
𝑘 𝑥𝑘 𝑦𝑘 Analytical Error
0 0 5 5 0
1 0.2 7 7.46208 -0.46208
2 0.4 9.808 11.15409 -1.34609
3 0.6 13.7632 16.70061 -2.93741
4 0.8 19.34048 25.03342 -5.69294
5 1 27.20467 37.54254 -10.3379
finite/Task Questions.pdf
University of Derby School of Electronics, Computing and Mathematics In-course Assignment Specification
Module Code and Title: 4MA502 – Mathematical Software Assignment No. and Title: 1 – Coursework Part 2 Assessment Tutor: Sam O’Neill Weighting Towards Module Grade: 40 % Date Set: 03/04/2020 Submission Date: 11/05/2020 – 23:59
Penalty for Late Submission
Recognising that deadlines are an integral part of professional workplace practice; the University expects students to meet all agreed deadlines for submission of assessments. However, the University acknowledges that there may be circumstances which prevent students from meeting deadlines. There are now 3 distinct processes in place to deal with differing student circumstances. https://www.derby.ac.uk/about/academic-regulations/ Assessed Extended Deadline (AED) Students with disabilities or long term health issues are entitled to a Support Plan. Exceptional Extenuating Circumstances (EEC) The EEC policy applies to situations where serious, unforeseen circumstances prevent the student from completing the assignment on time or to the normal standard. Late Submission Requests for late submission (LSR) will be made to the relevant Subject Manager in the School (or Head of Joint Honours for joint honours students) who can authorise an extension of up to a maximum of one week.
Level of Collaboration:
This is an individual assignment. No collaboration with other students or anyone else is allowed.
Learning Outcome(s) covered in this assignment: Demonstrate a knowledge of the underlying concepts of optimisation and metaheuristics and apply appropriate techniques to a range of problems; Derive solutions to various problems through the application and implementation of modern optimisation techniques.
Submissions in Turnitin and Blackboard You must submit your work using your student number to identify yourself, not your name. You must not use your name in the text of the work at any point. When you submit your work in Turnitin you must submit your student number within the assignment document and in the Submission title field in Turnitin.
Marking Criteria: Credit will be awarded for:
70–100%: Excellent
Outstanding; high to very high standard; a high level of critical analysis and evaluation; commendable originality; high quality presentation; exceptional clarity of ideas; excellent coherence and logic.
60-69%: Very good
A very good standard; a very good critical analysis and evaluation; significant originality; well researched; a very good standard of presentation; pleasing clarity of ideas; thoughtful and effective presentation; very good sense of coherence and logic;
50-59%: Good
A good standard; a fairly good level of critical analysis and evaluation; some evidence of original thinking; quite well researched; a good standard of presentation; ideas generally clear and coherent, some misunderstandings; some deficiencies in presentation.
40-49%: Satisfactory
A sound standard of work; a fair level of critical analysis and evaluation; little evidence of original thinking or originality; adequately researched; a sound standard of presentation; ideas fairly clear and coherent, some significant misunderstandings and errors; some weakness in style or presentation but satisfactory overall.
35-39%: Unsatisfactory (marginal fail)
Overall marginally unsatisfactory; some sound aspects but some of the following weaknesses are evident: inadequate critical analysis and evaluation; little evidence of originality; not well researched; standard of presentation unacceptable; ideas unclear and incoherent; some significant errors and misunderstandings.
1-34%: Very poor (fail)
Well below the pass standard; a poor critical analysis and evaluation; no evidence of originality; poorly researched; standard of presentation totally unacceptable; ideas confused and incoherent, some serious misunderstandings and errors. A clear fail, well short of the pass standard...The work demonstrates nothing of merit.
IMPORTANT GUIDELINES FOR SUBMISSION
All 4 questions must be answered using either Excel or MATLAB. You are encouraged to use other methods/means to verify your Excel/MATLAB solutions.
You are required to submit a report containing a write up of your answers/results and submit any Excel or MATLAB files that were used to in answering the questions.
This is an individual assignment. No collaboration with other students or anyone else is allowed. Please be aware that this is obvious when MATLAB/Excel files and report answers are extremely similar. You MUST not collude with other students, students expected of collusion may be penalised subject to the academic regulations
Question 1 Derive and implement a Forward Differences Scheme to numerically solve the following and provide a plot of your solution between 𝑥 = 0 and 𝑥 = 5.
Use a step size ℎ = 0.1, additional marks can be gained through analysis (e.g. errors, changes in step size etc…)
a) = 4𝑦, 𝑦(0) = 6
(15 marks)
b) = 𝑥𝑐𝑜𝑠(𝑥) + 2, 𝑦(0) = 8
(15 marks)
Question 2 Use Newton’s Method to solve the following to a tolerance of 0.001 using the given starting points 𝑥 . Provide a table of results and a plot of the iterations. Investigate whether the choice of 𝑥 matters?
i.e. successive terms should differ by less than or equal to 0.001. i.e. |𝑥 − 𝑥 | ≤ 0.001
a) 𝑥 + 3𝑥 + 4𝑥 + 3 = 0, 𝑥 = 1 (10 marks)
b) 3𝑥 + 3 = 𝑒 , 𝑥 = 3 (10 marks)
Question 3 Use numerical integration to evaluate the following, provide a table to summarise your results. How could you improve the evaluations?
a) ∫ sin , use 10 intervals, 𝑁 = 10
(10 marks)
b) ∫ √1 + 𝑥 , use 8 intervals, 𝑁 = 8 (10 marks)
Question 4 Answer the following problems:
a) The product of the first five natural numbers is,
1 ⋅ 2 ⋅ 3 ⋅ 4 ⋅ 5 = 5! = 120
The square of the sum of the first five natural numbers is,
(1 + 2 + 3 + 4 + 5) = 15 = 225
Hence the difference between the product of the first ten natural numbers and the square of the sum is 120 − 225 = −105.
Find the difference between the product of the first fifty natural numbers and the square of the sum of the first fifty natural numbers.
(6 marks)
b) By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 2021st prime number? Hint, a useful algorithm to look to implement is the Sieve of Eratosthenes
(12 marks)
c) You have the chance to play the following game. Each round cost £4 and you win £𝑛 per round, where 𝑛 is your score for that round. You can play as many rounds as you like. Each round is as follows - You roll a dice. If the dice lands on 3 then you can roll again, if it lands on anything else then you stop. Your score for the round is the total of all your rolls in that round. e.g. First round Roll 5, STOP Round Score 5 Second round Roll 3, Roll 3, Roll 1, STOP Round Score 3+3+1 = 7 Third round Roll 1, STOP Round Score 1 Total score after 3 rounds of 5+7+1 = 13 Therefore, you made a profit of £1 in total, as you played 3 rounds costing £12, but won back £13. a) Given that you have plenty of money to play with, would you keep playing the game? Use a simulation
to decide. b) If the game is changed so that you can continue to roll on a 1 instead of a 3. Would this affect the
choice of whether you would play? (12 marks)
Total 100 marks