Example

advertisement
Example
We start with the grid. In this example, the grid will be four by four.
0,0
0,1
1,0
0,2
1,1
2,0
2,1
3,0
3,1
0,3
1,2
1,3
2,2
2,3
3,2
3,3
Figure 1: A grid with four points.
The boundary data is given as follows:
u(x, 0) = sin
πx 2
, u(x, 1) = 1, u(0, y) = y, u(1, y) = 1.
Since there are four evenly spaced points along the x axis in our grid, the distance between each of them must
be 13 , and the distance is the same between points in the y direction. Let the points on the x axis be labled
x0 , . . . , xN and the points on the y axis be labled y0 , . . . , yN in increasing order. In our example, N = 3. Since
there are four points and the are equally spaced between 0 and 1, the distance between each of them must be
h = 1/N = 1/3. Then it must be that xi = ih and yj = jh for i, j = 0, . . . , N .
The boundary data imply that
u00 = u01 = u02 = u03 = 1,
u13 = u23 = u33 = 1,
u10 = y2 , u20 = y1 , u30 = y0 ,
πx πx 2
1
, u32 = sin
u31 = sin
2
2
Since these values are known, we only have to solve for u11 , u12 , u21 , and u22 . Setting each of these equal to the
average of the temperature of the points in the grid that lie on the circle of radius h from the point in question,
we find that
u10 + u12 + u01 + u21
⇒ 4u11 − u12 − u21 = u10 + u01
u11 =
4
u11 + u13 + u02 + u22
⇒ 4u12 − u11 − u22 = u13 + u02
u12 =
4
u20 + u22 + u11 + u31
⇒ 4u21 − u22 − u11 = u20 + u31 .
u21 =
4
u21 + u23 + u12 + u32
u22 =
⇒ 4u22 − u21 − u12 = u23 + u32 .
4
In general, these equations can be writen as
uij =
ui−1,j + ui+1,j + ui,j−1 + ui,j+1
, i, j = 1, . . . , N − 1.
4
In order to simplify things a little, we can think of the unknowns as the entries of a vector. Let k = j+(i−1)(N −1)
for 1 ≤ i, j ≤ N − 1. Then when i, j, and k are related in this way, we write uij = uk . For example, if the double
1
subscript is 11, then k = 1 + (1 − 1)(3 − 1) = 1. If the double subscript is 12, then k = 2 + (1 − 1)(3 − 1) = 2 and
so forth. The equations above become
4u1 − u2 − u3 = y2 + 1
−u1 + 4u2 − u4 = 1 + 1
−u1 + 4u3 − u4 = y1 + sin
−u2 − u3 + 4u4 = 1 + sin
which can be written as A~u = ~b,

4
 −1
A=
 −1
0
πx1
2
πx2
2
where


y2 + 1
−1 −1 0

1+1 4
0 −1 
 , ~b = 
 y1 + sin πx1
0
4 −1 
2 −1 −1 4
1 + sin πx2 2

5
3

 
=
 
2
1
5
6√
+ 23


.

We could solve this system by hand, but we’ll do it using Matlab since in the actual project you’ll be asked to do
this for N much larger than 3. To do this, we have to input the coefficient matrix into Matlab. Notice that this
matrix is only nonzero along certian “diagonals”. If N = 4, then the matrix looks like


4 −1 0 −1 0
0
0
0
0
 −1 4 −1 0 −1 0
0
0
0 


 0 −1 4
0
0 −1 0
0
0 


 −1 0
0
4 −1 0 −1 0
0 


 0 −1 0 −1 4 −1 0 −1 0  .


 0
0 −1 0 −1 4
0
0 −1 


 0
0
0 −1 0
0
4 −1 0 


 0
0
0
0 −1 0 −1 4 −1 
0
0
0
0
0 −1 0 −1 4
In the Matlab code that I have provided, I use the Matlab function spdiags to produce such a matrix.
When I plug the vector ~b above into the provided code, I get the following picture output:
1
0.8
0.6
0.4
0.2
0
1
0.8
1
0.6
0.8
0.6
0.4
0.4
0.2
0.2
0
0
Figure 2: Graph of the solution with N = 3
2
Download