Вы находитесь на странице: 1из 15

MOI UNIVERSITY

SCHOOL OF ENGINEERING
DEPARTMENT OF CIVIL AND STRUCTURAL ENGINEERING
MSC WATER ENGINEERING

Student: BARASA ONGETI


Number: TEC/PGCS/06/12

Course code: CVS 815


Course title: NUMERICAL METHODS
Task: ASSIGNMENT 1

Q1: Solution of initial value problems by Euler's method


Q2: Solution of initial value problems by Heun's method
Q3: Solution of two-point boundary value problem by the FDM
Q4: Solution of 2D boundary value problem by the FDM

PRESENTED TO: PROF. C. SITTERS

SUBMITTED ON: 25TH MAY, 2015


Q1: Solution of initial value problems by Euler's method
Solve the ODE dy dx  2x 3  12x 2  20x  8.5 analytically for x  0 to x  4 with the
initial value being y 0  1 .

Solution
Since f(x,y) is only a function of x, the exact solution can be found by direct
integration. Integration and substitution of the initial condition yields:
y  -0.5x 4 -4x 3 -10x 2 +8.5x+1
This equation is calculated on an Excel spreadsheet using 50 steps of x. The resulting
table is shown below

Interval Δx = 4
Number of Steps n = 50
Step size h = 0.08

ANALYTICAL SOLUTION USING 60 STEPS


x y (TRUE)
0 1
0.08 1.61393
0.16 2.08729
0.24 2.40705
0.32 2.55969
0.4 2.5312
0.48 2.30709
0.56 1.87236
0.64 1.21154
0.72 0.30864
0.8 -0.8528
0.88 -2.2897
0.96 -4.0196
1.04 -6.0604
1.12 -8.4305
1.2 -11.149
1.28 -14.235
1.36 -17.708
1.44 -21.59
1.52 -25.9
1.6 -30.661
1.68 -35.893
1.76 -41.621
1.84 -47.865
1.92 -54.65
2 -62

2
2.08 -69.939
2.16 -78.491
2.24 -87.682
2.32 -97.538
2.4 -108.08
2.48 -119.35
2.56 -131.36
2.64 -144.14
2.72 -157.73
2.8 -172.14
2.88 -187.41
2.96 -203.58
3.04 -220.66
3.12 -238.69
3.2 -257.7
3.28 -277.73
3.36 -298.8
3.44 -320.94
3.52 -344.2
3.6 -368.6
3.68 -394.19
3.76 -420.98
3.84 -449.02
3.92 -478.35
4 -509

Euler’s formula can be used to approximate the value of a function at a given point,
within a certain range. Euler’s formula is expressed as yi 1  yi  f ( xi , yi )h . The initial
condition and final condition is given as y0  1 and it is required to solve within the
range (xs = 0 and xf =4 ) the interpolations can be made with different values of step
size h. These are tabulated below.

EULER'S METHOD

USING h= 0.5
x f(xi,yi) yi (TRUE) yi Error εT
0 8.5 1 1 0
0.5 -4.75 2.21875 5.25 136.6197183
1 -25.5 -5 2.875 157.5
1.5 -55.25 -24.781 -9.875 60.15132409
2 -95.5 -62 -37.5 39.51612903
2.5 -147.75 -122.28 -85.25 30.28366982
3 -213.5 -212 -159.13 24.94103774
3.5 -294.25 -338.28 -265.88 21.40415704
4 -391.5 -509 -413 18.86051081

3
When a step size of h=0.5 is used, an error of 18.86% is obtained at x = 4. If the
step size is halved, the error at x = 4 is approximately reduced by half also to 9.62%.
Using a step size of h = 0.25, the results obtained are tabulated on the next page.

USING
h= 0.25
x f(xi,yi) yi (TRUE) yi Error εT
0 8.5 1 1 0
0.25 2.71875 2.43555 3.125 28.30793905
0.5 -4.75 2.21875 3.80469 71.47887324
0.75 -14.09375 -0.0957 2.61719 2834.693878
1 -25.5 -5 -0.9063 81.875
1.25 -39.15625 -13.033 -7.2813 44.13307358
1.5 -55.25 -24.781 -17.07 31.11601513
1.75 -73.96875 -40.877 -30.883 24.44932868
2 -95.5 -62 -49.375 20.36290323
2.25 -120.03125 -88.877 -73.25 17.58268322
2.5 -147.75 -122.28 -103.26 15.5571173
2.75 -178.84375 -163.03 -140.2 14.00812239
3 -213.5 -212 -184.91 12.78007075
3.25 -251.90625 -270.1 -238.28 11.77895567
3.5 -294.25 -338.28 -301.26 10.94457275
3.75 -340.71875 -417.56 -374.82 10.23653721
4 -391.5 -509 -460 9.626719057

On further reducing the step size to h  0.125 , the error at x  4 is further reduced.
The results of Euler’s method using this step size are tabulated below. The error at
x  4 is now 4.862%.

USING
h= 0.125
x f(xi,yi) yi (TRUE) yi Error εT
0 8.5 1 1 0
0.125 5.80859 1.89832 2.0625 8.648961482
0.25 2.71875 2.43555 2.78857 14.49478749
0.375 -0.793 2.56042 3.12842 22.18355185
0.5 -4.75 2.21875 3.0293 36.53169014
0.625 -9.1758 1.35339 2.43555 79.95850997
0.75 -14.094 -0.0957 1.28857 1446.428571
0.875 -19.527 -2.1915 -0.4731 78.41029354
1 -25.5 -5 -2.9141 41.71875
1.125 -32.035 -8.59 -6.1016 28.96872202
1.25 -39.156 -13.033 -10.106 22.45991308
1.375 -46.887 -18.404 -15 18.49518137
1.5 -55.25 -24.781 -20.861 15.81809584

4
1.625 -64.27 -32.244 -27.768 13.88366238
1.75 -73.969 -40.877 -35.801 12.41698122
1.875 -84.371 -50.766 -45.047 11.26425616
2 -95.5 -62 -55.594 10.33266129
2.125 -107.38 -74.672 -67.531 9.562817857
2.25 -120.03 -88.877 -80.954 8.914954401
2.375 -133.48 -104.71 -95.958 8.361418451
2.5 -147.75 -122.28 -112.64 7.882379249
2.625 -162.86 -141.69 -131.11 7.463239507
2.75 -178.84 -163.03 -151.47 7.093012112
2.875 -195.71 -186.43 -173.82 6.763266362
3 -213.5 -212 -198.29 6.467423349
3.125 -232.22 -239.85 -224.98 6.200272491
3.25 -251.91 -270.1 -254 5.957632205
3.375 -272.57 -302.87 -285.49 5.736106918
3.5 -294.25 -338.28 -319.56 5.532909931
3.625 -316.96 -376.47 -356.35 5.345732185
3.75 -340.72 -417.56 -395.97 5.172643632
3.875 -365.56 -461.7 -438.56 5.012018109
4 -391.5 -509 -484.25 4.862475442

The analytical solution and Euler’s approximations for the different step sizes are
plotted on one curve and it is as displayed below:

Plot of f(x,y) by Euler's Method


100

0
0 1 2 3 4 5
-100
h = 0.5
-200
h = 0.25
y

-300 h = 0.125

-400 True

-500

-600
X

It is noted from the plot that a reduction in the step size results in a closer
approximation.
Q2: Solution of initial value problems by Heun's method

5
Heun’s Method is a one-step predictor-corrector method. As derived in the class notes,
it can be expressed concisely as:
Predictor: y(i+1)0 = yi + f(x i ,yi )h

yi + f(x i ,yi )+ f(x (i+1) ,y(i+1) 0 )


Corrector: y(i+1) = h
2

Because the previous equation has 𝑦𝑖+1 on both sides of the equal sign, it can be
applied in an iterative fashion. In this exercise, the iteration was applied 10 times. The
resultant values are tabulated below and a plot is made.

Before the calculations commence, the true solution is determined analytically. The
analytical solution of the equation is:
4
y = (e0.8x - e-0.5x )+ 2e-0.5x
13
This formula can be used to generate the true solution values in the next table.
Analytical Slope at Slope at end Heun (1 Heun (10
solution beginning of interval Predictor iteration) iterations)
x y f(xi,yi) f(xi+1,yi+1j-1) yi0 yi1 f(xi+1,yi+110) yi10
0 2 3 6.4021637 2
1 6.1946313 5.5516227 13.685777 5 6.70108 5.721728 6.360864
2 14.8439219 11.6522387 30.106695 12.2527 16.31978 12.16100 15.30223
3 33.6771717 25.4930810 66.78395 27.97202 37.19924 26.72105 34.74327
4 75.3389621 56.4612371 4 62.69233 83.33776 59.26254 77.73508

By using the iterative scheme, the error between the true value and the approximation
is reduced. The table below shows the error reduction comparatively, using one
iteration in Heun’s method and using 10 iterations.

% RelError % RelError
(With 1 (With 10
iterations) iterations)

8.175635465 2.683498023
9.942520847 3.087532405
10.45835189 3.165631214
10.61708902 3.180442646

A comparative plot of these three methods is shown on the plot on the next page:

6
7
Q3: Solution of two-point boundary value problem by the FDM
The objective was to solve d2 y dx 2   x 2  1 y  0 analytically for the boundary
conditions y 0  10 and y 3  10 e 4.5 . A FDM method using a central difference
method is required to solve the problem in excel and to compare the analytical values
and the numerical values.

Solution
1
 x2
The analytical solution is of the form y  10(e 2
) . This is set into excel and the graph
is plotted as seen on the graph below. The graph can be compared to the numerical
solutions further below.

This problem was solved using Excel spreadsheet. The finite difference method was
(y -2y + y )
used, where the equation y ''  i+1 2i i-1 was programmed into the
h
spreadsheet. For ease of iteration, this equation is rearranged into the following form:

y
 yi 1  yi 1 
x h
2 2
 h 2 +2 
The value of x with a step of (3÷30 = 0.1) was put in the column. An iterative
procedure resulted in the column for the respective values of x based on the formula

8
as shown in the figure below. The value in the yellow cells was the boundary condition
and these were slotted in manually.

Similarly, cells were calculated for 10 nodes, 20 nodes and 5 nodes with their
respective h value. The figure on the next page shows the iteration for 30 nodes:

9
Using 5 intervals Using 20 Intervals
h x y h x y
0.60 0 10 0.15 0 10
0.60 8.31957605 0.15 9.889368063
1.00 6.520948914 0.3 9.561231837
1.20 4.722321778 0.45 9.037329389
1.80 1.873083276 0.6 8.351263362
2.40 0.534299128 0.75 7.544939142
3.00 0.111089965 0.9 6.664344428
1 6.209802035
Using 10 intervals 1.05 5.755259642
h 1.2 4.859447922
0.3 x y 1.35 4.011744738
0 10 1.5 3.238283904
0.3 9.564948664 1.65 2.555899805
0.6 8.346528041 1.8 1.972572799
0.9 6.647347413 1.95 1.488663461
1 5.740922279 2.1 1.098623658
1.2 4.834497153 2.25 0.792875756
1.5 3.213092987 2.4 0.559601653
1.8 1.953161787 2.55 0.386260887
2.1 1.086988005 2.7 0.260741633
2.4 0.554410843 2.85 0.172123839
2.7 0.259343287 3 0.111089965
3 0.111089965
z

The results obtained from each step-size were plotted in a graph of the function. The
resultant plot is shown below:

12

10

8
5 Nodes
6 10 Nodes
15 Nodes
4
30 Nodes
2

0
0 1 2 3 4

10
It can be noted that a higher number of nodes results in a smoother curve which
converges closer to the analytical solution. On comparing the errors at point, x  1 for
each of the analytical values, the table as shown is obtained.

Value at
(x=1) Error %
Analytical 6.065307 -
With 5 steps 6.520949 7.51
With 10 steps 5.736638 5.41
With 20 steps 6.209802 2.38
With 30 steps 6.062411 0.04

11
Q4: Solution of 2D boundary value problem by the FDM
The grid below is given, with the temperatures indicated. The objective is to use Excel
to solve for all internal temperatures.

y, j

1,1 1,2 Tt  210 0C 1,6

x ,i 2,1

3,1
Tl  120 C 0
Tr  60 0C

6,1 6,6
Tb  10 0C

Solution:
The central difference equation can be rewritten as:
Ti 1, j  2(  1)Ti , j  Ti 1, j  Ti , j 1  Ti , j 1  0
This equation is evaluated for each of the internal grid points and thus, 16 equations
with 16 unknown values are generated, and the following matrix is developed.

The matrix is solved using the MINVERSE and MMULT functions in Excel spreadsheet.
The unknown temperatures are then tabulated along with the known temperatures in
the table on the next page.

12
Temp Value (°C)
T2,2 142.8719
T2,3 146.8496
T2,4 138.1004
T2,5 113.785
T3,2 118.2555
T3,3 112.3348
T3,4 101.2249
T3,5 83.87656
T4,2 103.0355
T4,3 89.49582
T4,4 78.38591
T4,5 68.65656
T5,2 80.10964
T5,3 61.18985
T5,4 52.44066
T5,5 51.02278

A surface plot indicating the variation of these temperatures around the surface of the
thin plate is made, and appears as shown below.

250

200 200-250
Temperature (°C)

150-200
150
100-150
100
50-100
1
50 0-50
3
i
0
5
1 2 J --->
3 4 5 6

On the surface plot, the temperatures at the corner nodes are approximated by simple
averaging of two boundary temperatures relative to it.

13
Graphically, the representation below is made for all internal temperatures:

Once the temperatures are determined for each of the internal nodes, the heat fluxes
in x- and y- directions in all grid points are determined using a second order central
difference scheme, using the coefficient κ  2.1 J/(cm2 .s)
The heat fluxes are calculated in Excel. The following approximations are used:
T T Ti , j 1  Ti , j 1
qx ( i , j )   x i 1, j i 1, j and qy( i , j )   y
2x 2y
Appropriate approximations are made for the bottom, top, left and right boundary
temperatures using the procedure in the class notes. The following table is generated
from the Excel spreadsheet calculations.

14
Node Temp (°C) Y Direction X Direction Resultant Flux
T1,1 165 -11.8125 0 11.8125
T1,2 210 0 11.74742343 11.74742343
T1,3 210 0 11.05131736 11.05131736
T1,4 210 0 12.58242429 12.58242429
T1,5 210 0 16.83762415 16.83762415
T1,6 135 19.6875 0 19.6875
T2,1 120 -6.003864849 0 6.003864849
T2,2 142.871866 -3.524011976 8.027644125 8.767082217
T2,3 146.849615 0.626250643 8.545702746 8.568618633
T2,4 138.100433 4.339730085 9.517819747 10.46050429
T2,5 113.785005 10.25068178 11.03580114 15.06205112
T2,6 60 14.11856378 0 14.11856378
T3,1 120 0.457932375 0 0.457932375
T3,2 118.255496 1.006054118 3.485682201 3.627964346
T3,3 112.334826 2.235263432 5.01845677 5.493751994
T3,4 101.224917 3.735147599 5.225020308 6.422784817
T3,5 83.8765583 5.41077038 3.948738865 6.698430766
T3,6 60 6.267596566 0 6.267596566
T4,1 120 4.453181755 0 4.453181755
T4,2 103.035498 4.003673179 3.337762449 5.212490489
T4,3 89.4958234 3.235257803 4.475185616 5.522153507
T4,4 78.3859148 2.735153227 4.268622078 5.069733486
T4,5 68.6565607 2.413151319 2.874705785 3.753296237
T4,6 60 2.272347187 0 2.272347187
T5,1 120 10.47121972 0 10.47121972
T5,2 80.1096392 7.718832542 8.140606082 11.21828165
T5,3 61.1898473 3.631552876 6.955884547 7.84681503
T5,4 52.4406649 1.334427852 5.983767546 6.130756213
T5,5 51.0227779 -0.992162737 5.132449062 5.227467864
T5,6 60 -2.356520789 0 2.356520789
T6,1 65 14.4375 0 14.4375
T6,2 10 0 12.26918685 12.26918685
T6,3 10 0 8.958223277 8.958223277
T6,4 10 0 7.427116351 7.427116351
T6,5 10 0 7.178986141 7.178986141
T6,6 35 -6.5625 0 6.5625

15