Graphics Programs Reference
In-Depth Information
negative in order to satisfy the differentialequation. Nowwe are in a position to make
arough sketch of y :
y
1
x
0
2
Looking at the sketch it is clear that y (0)
1 and 2 appear to be
reasonable values for the brackets of y (0);if theyare not, Brent's methodwill display
an errormessage.
In the program listedbelowwe chose the nonadaptive Runge-Kuttamethod
( runKut4 )forintegration. Note thatthree user-supplied functions are needed to de-
scribe the problemathand. Apartfrom the function dEqs(x,y) that defines the
differentialequations, we also need the functions inCond(u) to specify the initial
conditionsforintegration, and residual(u) that provides Brent's methodwith the
boundary residual.Bychanging a few statements in these functions, the program
can be applied to any second-orderboundary value problem. It also works for third-
order equations if integrationisstartedat the end wheretwo of the three boundary
conditions arespecified.
>
0
.
5,sothat y (0)
=
function shoot2
% Shooting method for 2nd-order boundary value problem
% in Example 8.1.
global XSTART XSTOP H
% Make these params. global.
XSTART = 0; XSTOP = 2;
% Range of integration.
H = 0.1;
% Step size.
freq = 2;
% Frequency of printout.
u1=1;u2=2;
%Trialvaluesofunknown
% initial condition u.
x = XSTART;
u = brent(@residual,u1,u2);
[xSol,ySol] = runKut4(@dEqs,x,inCond(u),XSTOP,H);
printSol(xSol,ySol,freq)
functionF=dEqs(x,y) %First-orderdifferential
F = [y(2), -3*y(1)*y(2)]; % equations.
functiony=inCond(u)
%Initialconditions(uis
y = [0 u];
% the unknown condition).
Search WWH ::




Custom Search