runge

T
runge
(
T
)
(
in T x
,
T delegate(
in T
,
double
)
f
,
double time
,
double h
)
if (
hasBasicMathOp!T
)

Examples

1 import des.math.linear.vector;
2 
3 static struct Point 
4 { 
5     vec3 pos, vel; 
6     mixin( BasicMathOp!"pos vel" );
7 }
8 
9 auto v1 = Point( vec3(10,3,1), vec3(5,4,3) );
10 auto v2 = Point( vec3(10,3,1), vec3(5,4,3) );
11 assert( v1 + v2 == Point( vec3(20,6,2), vec3(10,8,6) ) );
12 assert( v1 * 2.0 == Point( vec3(20,6,2), vec3(10,8,6) ) );
13 
14 Point rpart( in Point p, double time )
15 { return Point( p.vel, vec3(0,0,0) ); }
16 
17 auto v = Point( vec3(10,3,1), vec3(5,4,3) );
18 
19 double time = 0, ft = 10, step = .01;
20 foreach( i; 0 .. cast(ulong)(ft/step+1) )
21     v = runge( v, &rpart, time+=step, step );
22 
23 assert( (v.pos - vec3(60,43,31)).len2 < 1e-5 );

Meta