Graphics Programs Reference
In-Depth Information
Solution
Letting
y
1
=
y
and
y
2
=
y
, we write the equivalent first-order equations as
y
1
y
2
y
2
y
=
F
(
x
,
y
)
=
=
−
0
.
1
y
2
−
x
which arecodedinthe following function:
_
functionF=fex7
4(x,y)
% Differential. eqs. used in Example 7.4
F = zeros(1,2);
F(1) = y(2); F(2) = -0.1*y(2) - x;
Comparing the function
fex7 4
here with
fex7 2
in Example 7.2 we note that it
is much simpler to input the differentialequationsfor the Runge-Kuttamethod than
for the Taylor series method. Here are the results of integration:
_
>> [x,y] = runKut4(@fex7
4,0,[0 1],2,0.25);
>> printSol(x,y,1)
x
y1
y2
0.0000e+000
0.0000e+000
1.0000e+000
2.5000e-001
2.4431e-001
9.4432e-001
5.0000e-001
4.6713e-001
8.2829e-001
7.5000e-001
6.5355e-001
6.5339e-001
1.0000e+000
7.8904e-001
4.2110e-001
1.2500e+000
8.5943e-001
1.3281e-001
1.5000e+000
8.5090e-001 -2.1009e-001
1.7500e+000
7.4995e-001 -6.0625e-001
2.0000e+000
5.4345e-001 -1.0543e+000
These results are the same asobtainedbythe Taylor seriesmethod inExample 7.2.
This wasexpected,since both methods are of the sameorder.
EXAMPLE 7.5
Use the fourth-order Runge-Kuttamethod to integrate
y
=
4
e
−
x
3
y
−
y
(0)
=
1
=
=
.
from
x
0to10 in stepsof
h
0
1. Compare the result with the analytical solution
e
−
x
.
y
=
Search WWH ::
Custom Search