|
CS 2073, Fall 2005 Program 9 Numerical Solution of Laplace's Equation Due (on time): 2005-11-14 23:59:59 Due (late): 2005-11-16 23:59:59 |
|
Program 9 must be emailed to:
nrwagner@cs.utsa.edu following directions for: running and submitting a C program, with deadlines:
|
#define M 30 /* height and width of box */
double t[M+2][M+2]; /* rows and columns */ char c[M+2][M+2]; /* matching character array */
void initialize(double t[M+2][M+2]); double step(double t[M+2][M+2]); /* one iteration, returns maximum change */ void store(double t[M+2][M+2], char c[M+2][M+2]); /* stores proper char in c */ void display(char c[M+2][M+2]); /* prints c out */
| Temperature key, temperature followed by letter | |||
|---|---|---|---|
32 Z
36 Y
40 Y
44 X
48 X
52 W
56 W
60 V
64 V
68 U
72 T
76 T
| 80 S
84 S
88 R
92 R
96 Q
100 Q
104 P
108 O
112 O
116 N
120 N
| 124 M 128 M 132 L 136 L 140 K 144 J 148 J 152 I 156 I 160 H 164 H 168 G | 172 G 176 F 180 E 184 E 188 D 192 D 196 C 200 C 204 B 208 B 212 A |

Above, the white boundary cells are not allowed to change value, while the cyan interior cells are the ones that change.
This "stubs" program actually compiles and runs, but it doesn't do anything. Most of the bodies of the functions are empty, but step ought to return something, so I just returned 0. (What would happen if you return 1 instead? Try it out and see.)
char alf[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Notice that 'A' is the same as alf[0] and 'Z' is the same as alf[25]. So we just want a linear function f such that f(32) = 25 and f(212) = 0. But this is easy:
f(T) = -25.0*T/180.0 + 25.0*212.0/180.0 = (212.0 - T)/7.2;
t[i][j] = (t[i-1][j] + t[i+1][j] +
t[i][j-1] + t[i][j+1])/4.0;
It is all-important that you apply the formula only to the cells colored cyan above. The boundary cells must not be touched. This is very clever on Kaufman's part: since the formula reaches out to cells outside the given cell, we would have to worry about an array subscript out of range if we had not kept the boundary as a "buffer".
Often in applications like this one, it's important to make use only of "old" values" (before the step), and then all at once change over to all the new values. In this case, though, it doesn't matter, and the end result will be the same either way.
|
Contents of email submission
for Program 9: Last Name, First Name; Course Number; Program Number.
|