Professional Documents
Culture Documents
y
i+1
i1
y 0 (xi ) =
2h
Then the ODE becomes,
yi+1 yi1
yi1 2yi + yi+1
+ yi = 0,
2
h
h
which can be written as,
yi1 (1 + h) + yi (h2 2) + yi+1 (1 h) = 0
and y0 = 2 , y10 = 1 (in the program, y(1) = 2, y(11) = 1)
We have employed the LU factorization to solve this problem. The Exact solution (solid
line) and the Numerical solution (o) are both provided. Exact solution:
y(x) = ex1 [x 2e(x 1)]
Absolute Max Error has also provided for you as a reference. Note that this error is NOT
the same as the one stated in the notes, cause the governing equation is different.
Code has been uploaded on the course web page. You are advised to try it out in Matlab.
2.4
2.2
1.8
1.6
1.4
1.2
0.2
0.4
0.6
Figure 1: Example 1
0.8
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0.2
0.4
0.6
Figure 2: Example 2
0.8
3. This example follows our Notes, Chapter 3. But our solution is differentiable up to first order.
u = 2, where 0 x 0.5
u = 1, where 0.5 x 1
and u(0) = 1, u(1) = 1
Same as Example 1, we have employed the Central Difference Scheme.
1
Set N=10 (total number of grids), h =
(grid length)
N
ui1 2ui + ui+1
u(xi ) =
h2
Exact Solution:
9
u(x) = x2 x + 1, where 0 x 0.5
8
1
21
u(x) = (x 1)2 (x 1) 1, where 0.5 x 1
2
8
Note that the solution is NOT smooth in this case and f does NOT exist. Thus, the
error term should NOT be close to 0, but a relatively acceptable range.
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
0.2
0.4
0.6
0.8
Figure 3: Example 3
To summarize the maximum absolute error vs grid length for all the above 3 cases:
h
0.1
0.01
0.001
Example 1 0.0018
0.1772 104
0.0018 104
13
13
Example 2 0.0011 10
0.0214 10
0.8918 1013
Example 3 0.0125
0.0013
0.0001
Note that in both Examples 1 and 3, when you decrease the grid length, the degree of accuracy is increased. However, for Example 2, since the error size is near the built-in the
Matlab, instability will become significant when you decrease the grid length.
0.25
0.2
0.15
0.1
0.05
0.2
0.4
0.6
Figure 4: Example 4
0.8
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
0.2
0.4
0.6
Figure 5: Example 5
0.8
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0.2
0.4
0.6
0.8
Figure 6: Example 6
Note that you may check the error by the program attached.