Eso208 Tutorial Solution
Eso208 Tutorial Solution
Eso208 Tutorial Solution
Q1 a) Using natural spline, S”(0)=S”(8)=0. From the tridiagonal system, equations for S”(2)
and S”(4) are written as below, and solved to get their values.
(xi − x i −1 )Si′′−1 + 2(xi +1 − x i −1 )Si′′+ (xi +1 − x i )Si′′+1
f ( xi +1 ) − f ( xi ) f ( xi ) − f ( xi −1 )
=6 −6
xi +1 − xi xi − xi −1
Equations For S" Gauss Elimination: S" at x=2 and
x=4
at x=2 and 4
x f(x)
4 0.6300
8 0.3968
Si ( x) =
( xi +1 − x ) Si′′( xi ) + ( x − x i ) Si′′( xi +1 )
3 3
0 1.0000 0.0000 0 0
Q2)
t v Acceleration
1 0.65
2 1.72
3 3.48
4 6.39
8 53.6
9 89.02
10 147.41
− 3 f i + 4 f i +1 − f i + 2 3 f i − 4 f i −1 + f i − 2 ′ f −f
f i′ = f i′ = f i = i +1 i −1
2h 2h 2h
Tutorial 7 - Solution
Q1)
t v Simp 1/3 Simp 3/8 Trap h=1 Trap h=2 Trap h=4
0 0 0.33 1.72 12.78
1 0.65 1.44 3.97 1.19
2 1.72 2.60 8.11
3 3.48 7.34 4.94
4 6.39 28.23 8.79 25.48 119.98
5 11.18 23.40 15.14
6 19.09 25.61 72.69
7 32.12 67.06 136.98 42.86
8 53.6 71.31 201.01 912.06
9 89.02 185.70 118.22
10 147.41 624.28 195.55 549.84
11 243.69 508.20 323.06
12 402.43
793.14 793.46 809.57 858.85 1044.82
The distance travelled in 12 minutes is: 793.14 cm using Simpson’s 1/3 rule, 793.46 cm using
3/8 rule, and 792.89 cm using Romberg integration with three trapezoidal estimates (809.57
using h=1, 858.85 using h=2, 1044.82 using h=4). Note that the Romberg, O(h4), with h=1 and
2, is same as Simpson’s 1/3. Also note that 1/3 rule is more accurate than 3/8 (assuming
Romberg to be the best estimate).
Q2)
𝑟𝑟 1/7
The table below shows the computation of Iz and I: 𝑓𝑓 = 2𝜋𝜋𝜋𝜋 × 2 �1 − �
0.12
3-point z w r f w.f
-0.77460 0.555556 0.013524 0.167072 0.092818
0 0.888889 0.060000 0.682900 0.607022
0.77460 0.555556 0.106476 0.979540 0.544189 I Error (%)
Iz 1.244028 0.074642 -1.01697
4-point z w r f w.f
-0.86114 0.347855 0.008332 0.103630 0.036048
-0.33998 0.652145 0.039601 0.469970 0.306489
0.33998 0.652145 0.080399 0.862339 0.56237
0.86114 0.347855 0.111668 0.958623 0.333462 I Error (%)
Iz 1.238368 0.074302 -0.55737
Tutorial 8: Solution
1. Solve the differential equation dy/dt = −100 y + 99 e−t with the initial condition y(0)=2 using,
(a) Euler’s forward (explicit) method, and (b) Euler backward (implicit) method, to obtain the
value of y at t=0.1. Use time steps of 0.01, 0.02 and 0.025. Find the analytical solution and
compare the errors for these time steps.
Solution:
The analytical solution is y= e−t+ e−100t
Clearly, explicit method is unstable for step size of 0.025, and is oscillating in a finite band for
0.02.
2. The amount of lowering of water level, s, in a well at a time t, due to pumping from
groundwater is governed by an equation of the form s=C W(u), where C is a constant
(proportional to the discharge), W is called the Well Function, and u is inversely proportional
to t. The well function is given by the equation dW(u)/du = −Exp(−u)/u. If the value of W(1) is
0.21938393, find the value of W(0.5) using (a) Romberg integration algorithm with accuracy
O(h6) (b) Modified Euler with h= −0.5 (c) Heun’s method with h= −0.25 and (d) Fourth-order
Runge-Kutta method with h= −0.25. Perform an error analysis using the true value of W(0.5)
as 0.55977359.
Solution:
f(u)=dW/du=-Exp(-u)/u Romberg I=From 0.5 to 1 Modified Euler
k1 -0.36788 -0.62982
k2 -0.47641 -0.85642
k3 -0.47641 -0.85642
k4 -0.62982 -1.21306
1. Solve the differential equation dy/dx = x2y − 2y with y(0)=1 over the interval x=0 to 0.5, using
(a) Heun’s method without iteration with h=0.25 and 0.125, (b) Heun’s method with iteration (with
h=0.25 and stopping error criterion of 1%), and (c) 4th order Runge-Kutta method with h=0.125 and
0.25. Obtain the exact value of y at x=0.5 and perform an error analysis.
Solution: f(x,y) = x2y − 2y. Exact solution is y=exp(x3/3-2x) and value at 0.5 is 0.383531573.
h= 0.125
xi yi f(xi,yi) y0 xi+1 f(xi+1,y0) yi+1
0 1 -2 0.75 0.125000 -1.488281 0.78198242
0.125000 0.7819824 -1.55175 0.58801 0.250000 -1.139277 0.61379344
0.250000 0.6137934 -1.18922 0.46514 0.375000 -0.864870 0.48541249
0.375000 0.4854125 -0.90256 0.37259 0.500000 -0.652036 0.388250 -0.004718
2. Solve the differential equation dy/dx = 10 sin(πx) with the initial condition y(0)=0 and step length of
0.2 using (a) the 4th order R-K method, (b) the Milne’s method and (c) 4th order Adams method to
obtain the value of y at t=0.2, 0.4, 0.6, 0.8 and 1.0. (For the multi-step methods use the values obtained
from the R-K method for start-up)
Solution: f(x,y) = 10 sin(πx). Exact solution is (10-10 cos πx)/π and the values are:
Adams' h= 0.2
Find y(0.8), y(1)
Milne's h= 0.2 f(x,y)
Find y(0.8), y(1) y(0.8)^0 5.6623 5.8779
f(x,y) y(0.8)^1 5.7663 5.8779
y(0.8)^0 5.6710 5.8779 y(0.8)^2 5.7663 5.8779
y(0.8)^1 5.7616 5.8779
y(0.8)^2 5.7616 5.8779
Solution:
(a) Note that Ralston’s method has been used to solve the IVP
f1=dy1/dx=y2
f2=dy2/dx=3+2y1-2x+y2
h= 0.25
Assume y2(0)=0 Assume y2(0)=1
x y1 y2 f1 f2 x y1 y2 f1 f2
0 0 0 0 3 0 0 1 1 4
0.1875 0 0.5625 0.5625 3.1875 0.1875 0.1875 1.75 1.75 4.75
0.25 0.09375 0.78125 0.25 0.375 2.125
x y1 y2 f1 f2 x y1 y2 f1 f2
0.25 0.09375 0.78125 0.78125 3.46875 0.25 0.375 2.125 2.125 5.375
0.4375 0.24023 1.43164 1.43164 4.03711 0.4375 0.77344 3.13281 3.13281 6.80469
0.5 0.39746 1.74316 0.5 1.07422 3.70703
x y1 y2 f1 f2
0 0 0.44217 0.44217 3.44217
0.1875 0.08291 1.08757 1.08757 3.87838
0.25 0.21811 1.37541
x y1 y2 f1 f2
0.25 0.21811 1.37541 1.37541 4.31163
0.4375 0.476 2.18384 2.18384 5.26084
0.5 0.6967 2.61152
Note: 0.21811 may be directly obtained by linear interpolation between 0.09375 and 0.375
(b) There are three nodes: at 0, 0.25, and 0.5. Only one unknown, y(0.25).
With the known values of x1=0.25, y0=0 and y2=0.6967, we get y1=0.21335 (compared to 0.21811)
Solution: T=0
j=4
j=3
∂T/∂x=0 T=100
j=2
j=1
j=0
i=0 i=1 i=2
T=0
The discretization is shown above. We need to find T1,2. (Six unknowns are T0,1, T0,2, T0,3, T1,1, T1,2, and
T1,3)
𝜕𝜕2 𝑇𝑇 𝜕𝜕2 𝑇𝑇
The governing equation is 2
+ = 0. The nodal equation, using central difference
𝜕𝜕𝑥𝑥 𝜕𝜕𝑦𝑦 2
𝑇𝑇𝑖𝑖+1,𝑗𝑗 −2𝑇𝑇𝑖𝑖,𝑗𝑗 +𝑇𝑇𝑖𝑖−1,𝑗𝑗 𝑇𝑇𝑖𝑖,𝑗𝑗+1 −2𝑇𝑇𝑖𝑖,𝑗𝑗 +𝑇𝑇𝑖𝑖,𝑗𝑗−1
approximation for the second derivative is + = 0. Since ∆x
∆𝑥𝑥 2 ∆𝑦𝑦 2
and ∆y are equal, −𝑇𝑇𝑖𝑖,𝑗𝑗−1 − 𝑇𝑇𝑖𝑖−1,𝑗𝑗 + 4𝑇𝑇𝑖𝑖,𝑗𝑗 − 𝑇𝑇𝑖𝑖,𝑗𝑗+1 − 𝑇𝑇𝑖𝑖+1,𝑗𝑗 = 0.
Using ghost nodes (i=−1), 𝑇𝑇−1,𝑗𝑗 = 𝑇𝑇1,𝑗𝑗 . The system of equation is:
4 − 2 −1 T0,1 0
− 1 4 0 −1 T 100
1,1
− 1 0 4 − 2 −1 T0, 2 0
=
− 1 − 1 4 0 − 1 T1, 2 100
−1 0 4 − 2 T0,3 0
− 1 − 1 4 T1,3 100
Set-up the matrix equations for the solution of the above equation in terms of Courant Number (or
CFL number) and Grid Peclet Number for general ∆x and ∆t :
𝑣𝑣∆𝑡𝑡
Courant or CFL No. 𝐶𝐶 =
∆𝑥𝑥
𝑣𝑣∆𝑥𝑥
Grid Peclet No. 𝑃𝑃𝑒𝑒 =
𝐷𝐷
Solution:
Using forward difference for time derivative and central for the space (time is denoted by superscript,
n, and space by subscript, i), we get (for spatial variables, using a weight of μ for the known time step,
n, and a weight of 1−μ for the unknown time step, n+1)
𝑐𝑐𝑛𝑛+1
𝑖𝑖 − 𝑐𝑐𝑛𝑛𝑖𝑖 𝑐𝑐𝑛𝑛+1 − 𝑐𝑐𝑛𝑛+1 𝑐𝑐𝑛𝑛 − 𝑐𝑐𝑛𝑛𝑖𝑖−1
+ 𝑣𝑣 �(1 − 𝜇𝜇) 𝑖𝑖+1 𝑖𝑖−1
+ 𝜇𝜇 𝑖𝑖+1 �
∆𝑡𝑡 2∆𝑥𝑥 2∆𝑥𝑥
𝑛𝑛+1
𝑐𝑐𝑛𝑛+1
𝑖𝑖+1 − 2𝑐𝑐𝑖𝑖 + 𝑐𝑐𝑛𝑛+1
𝑖𝑖−1 𝑐𝑐𝑛𝑛𝑖𝑖+1 − 2𝑐𝑐𝑛𝑛𝑖𝑖 + 𝑐𝑐𝑛𝑛𝑖𝑖−1
− 𝐷𝐷 �(1 − 𝜇𝜇) + 𝜇𝜇 �
∆𝑥𝑥2 ∆𝑥𝑥2
𝑛𝑛+1
+ 𝑘𝑘 �(1 − 𝜇𝜇)𝑐𝑐𝑖𝑖 + 𝜇𝜇𝑐𝑐𝑛𝑛𝑖𝑖 � = 0
𝐶𝐶 𝐶𝐶 𝑛𝑛+1
𝐶𝐶 𝐶𝐶 𝐶𝐶
�(1 − 𝜇𝜇) �− − �� 𝑐𝑐𝑖𝑖−1 + �1 + (1 − 𝜇𝜇) �𝑘𝑘∆𝑡𝑡 + 2 �� 𝑐𝑐𝑖𝑖𝑛𝑛+1 + �(1 − 𝜇𝜇) � − �� 𝑐𝑐𝑖𝑖+1
𝑛𝑛+1
2 𝑃𝑃𝑒𝑒 𝑃𝑃𝑒𝑒 2 𝑃𝑃𝑒𝑒
𝐶𝐶 𝐶𝐶 𝑛𝑛
𝐶𝐶 𝐶𝐶 𝐶𝐶
= �𝜇𝜇 � + �� 𝑐𝑐𝑖𝑖−1 + �1 − 𝜇𝜇 �𝑘𝑘∆𝑡𝑡 + 2 �� 𝑐𝑐𝑖𝑖𝑛𝑛 + �𝜇𝜇 �− + �� 𝑐𝑐𝑖𝑖+1
𝑛𝑛
2 𝑃𝑃𝑒𝑒 𝑃𝑃𝑒𝑒 2 𝑃𝑃𝑒𝑒
Or,
𝑛𝑛+1
𝑎𝑎𝑖𝑖,𝑖𝑖−1 𝑐𝑐𝑖𝑖−1 + 𝑎𝑎𝑖𝑖,𝑖𝑖 𝑐𝑐𝑖𝑖𝑛𝑛+1 + 𝑎𝑎𝑖𝑖,𝑖𝑖+1 𝑐𝑐𝑖𝑖+1
𝑛𝑛+1
= 𝑏𝑏𝑖𝑖
The matrix form is (given c 0a=0 a1, 2derivative=zero at the nth node)
1,1 and c1n +1 b1
a n +1
2,1 a2, 2 a2,3 c2 b2
a3 , 2 a 3 , 3 a3 , 4 c3n +1 b3
=
. . . . .
an −1, n − 2 an −1, n −1 an −1, n cnn−+11 bn −1
an , n −1 + an , n +1 an , n cnn +1 bn