Graphics Programs Reference
In-Depth Information
Using the finite difference approximation
y
(
m
)
(
x
y
(
m
)
(
x
)
+
h
)
−
y
(
m
+
1)
(
ξ
)
≈
h
weobtain the more usable form
h
m
(
m
1)!
y
(
m
)
(
x
y
(
m
)
(
x
)
E
≈
+
h
)
−
(7.7)
+
which couldbe incorporatedinthe algorithm to monitor the errorineach integration
step.
taylor
The function
taylor
implements the Taylor seriesmethod of integration of order four.
It can handle any number of first-orderdifferentialequations
y
i
=
f
i
(
x
,
y
1
,
y
2
,...,
y
n
),
i
=
1
,
2
,...,
n
. The useris required to supply the function
deriv
that returns the 4
×
n
array
⎡
⎣
⎤
⎦
=
⎡
⎣
⎤
⎦
(
y
)
T
(
y
)
T
(
y
)
T
(
y
(4)
)
T
y
1
y
2
y
n
···
y
1
y
2
···
y
n
d
=
y
1
y
2
y
n
···
y
(4)
1
y
(4)
2
···
y
(4)
n
The functionreturns the arrays
xSol
and
ySol
thatcontain the values of
x
and
y
at intervals
h
.
function [xSol,ySol] = taylor(deriv,x,y,xStop,h)
% 4th-order Taylor series method of integration.
% USAGE: [xSol,ySol] = taylor(deriv,x,y,xStop,h)
% INPUT:
% deriv = handle of function that returns the matrix
% d = [dy/dx dˆ2y/dxˆ2 dˆ3y/dxˆ3 dˆ4y/dxˆ4].
% x,y = initial values; y must be a row vector.
% xStop = terminal value of x
% h = increment of x used in integration (h > 0).
% OUTPUT:
% xSol = x-values at which solution is computed.
% ySol = values of y corresponding to the x-values.
ifsize(y,1)>1;y=y';end %ymustberowvector
xSol = zeros(2,1); ySol = zeros(2,length(y));
xSol(1) = x; ySol(1,:) = y;
Search WWH ::
Custom Search