Graphics Programs Reference
In-Depth Information
3.
Having determined the valueof
u
, solve the differentialequationsonce more and
record the results.
If the differentialequationislinear, any root-finding methodwill need only one
interpolation to determine
u
.Butsince Brent's methoduses quadratic interpolation,
it needsthree points:
u
1
,
u
2
and
u
3
, the latterbeing providedbyabisection step. This
is wasteful, since linear interpolationwith
u
1
and
u
2
wouldalso result in the correct
valueof
u
. Therefore, we replace Brent's methodwith linear interpolationwhenever
the differentialequationislinear.
linInterp
Here is the algorithm for linear interpolation:
function root = linInterp(func,x1,x2)
% Finds the zero of the linear function f(x) by straight
% line interpolation between x1 and x2.
% func = handle of function that returns f(x).
f1 = feval(func,x1); f2 = feval(func,x2);
root=x2-f2*(x2-x1)/(f2-f1);
EXAMPLE 8.1
Solve the nonlinear boundary value problem
y
+
3
yy
=
0
y
(0)
=
0
y
(2)
=
1
Solution
The equivalent first-order equations are
y
1
y
2
y
2
−
y
=
=
3
y
1
y
2
with the boundary conditions
y
1
(0)
=
0
y
1
(2)
=
1
y
(0), the
unspecified initialcondition. Wecouldalways pick two numbers at randomand hope
for the best. However, it is possible to reduce the elementofchance with a little
detective work.Westart by making the reasonable assumption that
y
issmooth (does
not wiggle) in the interval0
Now comes the daunting task of estimating the trial values of
y
2
(0)
=
≤
≤
x
2. Next we note that
y
hastoincrease from 0to1,
which requires
y
>
0.Since both
y
and
y
are positive, weconcludethat
y
must be
Search WWH ::
Custom Search