Runge-Kutta method: Difference between revisions

move Octave section to restore alphabetic order
(incomplete octave entry)
(move Octave section to restore alphabetic order)
Line 585:
t = 9.000000, y = 451.562459, err = 4.07232e-05
t = 10.000000, y = 675.999949, err = 5.09833e-05</pre>
 
=={{header|Octave}}==
{{incomplete}}
Implementing Runge-Kutta in octave is a bit of a hassle. For now we'll showcase how to solve an ordinary differential equation using the lsode function.
 
<lang octave>function ydot = f(y, t)
ydot = t * sqrt( y );
endfunction
 
t = [0:10]';
y = lsode("f", 1, t);
 
[ t, y, y - 1/16 * (t.**2 + 4).**2 ]</lang>
{{out}}
<pre>ans =
 
0.00000 1.00000 0.00000
1.00000 1.56250 0.00000
2.00000 4.00000 0.00000
3.00000 10.56250 0.00000
4.00000 25.00000 0.00000
5.00000 52.56250 0.00000
6.00000 100.00000 0.00000
7.00000 175.56250 0.00000
8.00000 289.00001 0.00001
9.00000 451.56251 0.00001
10.00000 676.00001 0.00001</pre>
 
=={{header|PARI/GP}}==
Line 696 ⟶ 723:
y( 9) = 451.562459 ± 4.072316e-05
y(10) = 675.999949 ± 5.098329e-05</pre>
 
=={{header|Octave}}==
{{incomplete}}
Implementing Runge-Kutta in octave is a bit of a hassle. For now we'll showcase how to solve an ordinary differential equation using the lsode function.
 
<lang octave>function ydot = f(y, t)
ydot = t * sqrt( y );
endfunction
 
t = [0:10]';
y = lsode("f", 1, t);
 
[ t, y, y - 1/16 * (t.**2 + 4).**2 ]</lang>
{{out}}
<pre>ans =
 
0.00000 1.00000 0.00000
1.00000 1.56250 0.00000
2.00000 4.00000 0.00000
3.00000 10.56250 0.00000
4.00000 25.00000 0.00000
5.00000 52.56250 0.00000
6.00000 100.00000 0.00000
7.00000 175.56250 0.00000
8.00000 289.00001 0.00001
9.00000 451.56251 0.00001
10.00000 676.00001 0.00001</pre>
 
=={{header|Python}}==
1,934

edits