Graphics Programs Reference
In-Depth Information
+
K
1
/
2. The second equation then approximates the area of the panel by the area
K
2
of the cross-hatchedrectangle. The error here is proportional to the curvature
y
of the plot.
y
(
x
)
Fourth-Order Runge-Kutta Method
The fourth-order Runge-Kuttamethodisobtained from the Taylor series along the
samelines as the second-ordermethod. Since the derivationis rather longandnot very
instructive, weskip it. The finalform of the integration formula again dependson the
choice of the parameters; that is, there isno uniqueRunge-Kutta fourth-order formula.
The most popular version, which isknown simplyas the
Runge-Kuttamethod
,entails
the following sequence of operations:
K
1
=
h
F
(
x
,
y
)
h
F
x
h
2
,
K
1
2
K
2
=
+
y
+
h
F
x
h
2
,
K
2
2
K
3
=
+
y
+
(7.10)
K
4
=
+
,
+
h
F
(
x
h
y
K
3
)
1
6
(
K
1
y
(
x
+
h
)
=
y
(
x
)
+
+
2
K
2
+
2
K
3
+
K
4
)
Themaindrawback of thismethodisthat it doesnot lenditself to anestimate of the
truncation error. Therefore, we must guess the integration step size
h
,ordetermine
it by trial and error. In contrast, the so-called
adaptive methods
can evaluate the
truncation errorineach integration step and adjust the valueof
h
accordingly (but at
a higher cost of computation). Onesuch adaptive methodis introducedinthe next
article.
runKut4
The function
runKut4
implements the Runge-Kuttamethod of order four. The user
must provide
runKut4
with the function
dEqs
that defines the first-orderdifferential
equations
y
=
F
(
x
,
y
).
function [xSol,ySol] = runKut4(dEqs,x,y,xStop,h)
% 4th-order Runge--Kutta integration.
% USAGE: [xSol,ySol] = runKut4(dEqs,x,y,xStop,h)
% INPUT:
% dEqs = handle of function that specifies the
Search WWH ::
Custom Search