358 CHAPTER 9. NUMERICAL METHODS
>
N:=25: L:=1.0: h:=L/(N+1); r:=0.05: k:=r*hˆ2; numplots:=100:
h := 0.03846153846 k := 0.00007396449705
Using the BandMatrix command, the relevant matrix A is entered. The diagonal
entries are given by 1 − 2 r =0.90, the subdiagonal entries by r =0.05. The
number 1 indicates that there is one subdiagonal and N gives the size of the
matrix, i.e., N × N. For brevity, the output shown here in the text has been
truncated, only 5 of the 25 rows being shown.
>
A:=BandMatrix([r,1-2*r,r],1,N);
A:= [0.90, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0.05, 0.90, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0]
[0, 0.05, 0.90, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[...............................................................................................................]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0.05, 0.90, 0.05]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.05, 0.90]
A functional operator f is formed for generating the values of the initial tem-
perature profile at the internal spatial grid points.
>
f:=x->evalf(200*xˆ3*(L-x)):
Using f, the values of the temperature at the internal x mesh points on the
zeroth time row are formed into a column vector v. Again, only a few of the 25
entries are shown here in the text.
>
v:=Vector([[seq(f(i*h),i=1..N)]]);
v :=
⎡
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎣
0.01094149364
0.08403067118
0.2717867022
..................
..................
21.01335738
..................
..................
12.10041666
6.838433534
⎤
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎦
To establish the vertical scale of our plot, the following max command is used
to select the largest temperature value from the sequence of entries in v.
>
vmax:=max(seq(v[i],i=1..N));
vmax := 21.01335738
The start time for the following do loop, which carries out the requisite matrix
multiplication, is recorded.
>
begin:=time():
The do loop runs from n =1 to numplots. The matrix multiplication is carried
out in T, a plot being produced on every 20th time step. For plotting purposes