Math-RungeKutta

 view release on metacpan or  search on metacpan

examples/three-body

	($t, $dt, @y) = &rk4_auto( \@y, \&dydt, $t, $dt, $epsilon );
	($t_midpoint, @y_midpoint) = &rk4_auto_midpoint();
   &display($t_midpoint, @y_midpoint);
	&display($t, @y);
}
&move (0,$maxrows-1);
exit 0;

sub dydt { my ($t, @y) = @_;
	# t  x0 y0 vx0 vy0  x1 y1 vx1 vy1  x2 y2 vx2 vy2
	my @dydt; local $[=0;

	$dydt[0] = $y[2];  $dydt[1] = $y[3];
	$dydt[4] = $y[6];  $dydt[5] = $y[7];
	$dydt[8] = $y[10]; $dydt[9] = $y[11];

	$dist01squared = ($y[0]-$y[4])**2 + ($y[1]-$y[5])**2;
	$dist02squared = ($y[0]-$y[8])**2 + ($y[1]-$y[9])**2;
	$dist12squared = ($y[4]-$y[8])**2 + ($y[5]-$y[9])**2;

	if ($dist01squared < .0001) {  # should perhaps collide & coalesce ...

lua/three-body.lua

	io.write(string.format("\027[%d;%dH", y+1, x+1))
end
function bold    () io.write("\027[1m") end
function normal  () io.write("\027[0m") end
function clear   () io.write("\027[H\027[J") end
function reverse () io.write("\027[7m") end


function dydt(t, y)
	-- t  x0 y0 vx0 vy0  x1 y1 vx1 vy1  x2 y2 vx2 vy2
	local dydt = {} -- $[=0;

	dydt[1] = y[3];  dydt[2]  = y[4];
	dydt[5] = y[7];  dydt[6]  = y[8];
	dydt[9] = y[11]; dydt[10] = y[12];

	local dist01squared = (y[1]-y[5])^2 + (y[2]-y[6])^2
	local dist02squared = (y[1]-y[9])^2 + (y[2]-y[10])^2
	local dist12squared = (y[5]-y[9])^2 + (y[6]-y[10])^2

	if dist01squared < .0001 then  -- should perhaps collide & coalesce ...

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.481948 second using v1.00-cache-1.03-grep-7fa205e-cpan-6421e59f23b )