Graphics Programs Reference
In-Depth Information
EXAMPLE 8.6
Write out Eqs. (8.11)for the following linear boundary value problemusing n
=
11:
y =−
y (
4 y
+
4 x
y (0)
=
0
π/
2)
=
0
Solve these equations with a computerprogram.
Solution In thiscase
α =
0 applicable
to y ),
β =
0 applicable
to y ) and
y )
f ( x
,
y
,
=−
4 y
+
4 x . Hence Eqs. (8.11) are
y 1 =
0
h 2 (
y i 1
2 y i +
y i + 1
4 y i +
4 x i )
=
0,
i
=
2
,
3
,...,
10
h 2 (
2 y 10
2 y 11
4 y 11 +
4 x 11 )
=
0
or, using matrix notation
1
0
y 1
y 2
.
y 10
y 11
0
4 h 2 x 2
.
4 h 2 x 10
4 h 2 x 11
4 h 2
1
2
+
1
. . .
. . .
. . .
=
1
2
+
4 h 2
1
4 h 2
2
2
+
Note that the coefficient matrix istridiagonal, so that the equationscan be solved
efficientlybythe functions LUdec3 and LUsol3 describedinArt.2.4.Recalling that
these functions store the diagonals of the coefficient matrix in vectors c
,
d and e , we
arrive at the following program:
function fDiff6
% Finite difference method for the second-order,
% linear boundary value problem in Example 8.6.
xStart = 0; xStop = pi/2;
% Range of integration.
n=11;
%Numberofmeshpoints.
freq = 1;
% Printout frequency.
h = (xStop - xStart)/(n-1);
x = linspace(xStart,xStop,n)';
[c,d,e,b] = fDiffEqs(x,h,n);
[c,d,e] = LUdec3(c,d,e);
printSol(x,LUsol3(c,d,e,b),freq)
Search WWH ::




Custom Search