Graphics Programs Reference
In-Depth Information
represent the initial time and j=1 represent the left endpoint. Notice also
that in the first line following the for statement, we compute an entire row
of u , except for the first and last values, in one line; each term is a vector of
length J-2 , withthe index j increased by 1 in the term u(n,3:J) and
decreased by 1 in the term u(n,1:J-2) .
Let's use the M-file above to solve the one-dimensional heat equation with
k = 2 on the interval 5 x 5 from time 0 to time 4, using boundary
temperatures 15 and 25, and initial temperature distribution of 15 for x < 0
and 25 for x > 0. You can imagine that two separate wires of length 5 with
different temperatures are joined at time 0 at position x = 0, and eachof
their far ends remains in an environment that holds it at its initial
temperature. We must choose values for t and x ; let's try t = 0 . 1 and
x = 0 . 5, so that there are 41 values of t ranging from 0 to 4 and 21 values
of x ranging from 5to5.
tvals = linspace(0, 4, 41);
xvals = linspace(-5, 5, 21);
init = 20 + 5*sign(xvals);
uvals = heat(2, xvals, tvals, init, [15 25]);
surf(xvals, tvals, uvals)
xlabel x; ylabel t; zlabel u
x 10 12
1
0.5
0
0.5
1
3
5
2
0
1
0
5
t
x
Search WWH ::




Custom Search