Math-RungeKutta
view release on metacpan or search on metacpan
RungeKutta.pm view on Meta::CPAN
which all begin with the letters C<_rk_> so you should
avoid introducing variables beginning with these characters.
=head1 LUA
In the C<lua/> subdirectory of the install directory there is
I<RungeKutta.lua>, which is an exact translation of this Perl code into Lua.
The function names and arguments are unchanged.
Brief Synopsis:
local RK = require 'RungeKutta'
function dydt(t, y) -- the derivative function
-- y is the table of the values, dydt the table of the derivatives
local dydt = {}; ... ; return dydt
end
y = initial_y(); t=0; dt=0.4; -- the initial conditions
-- For automatic timestep adjustment ...
while t < tfinal do
t, dt, y = RK.rk4_auto(y, dydt, t, dt, 0.00001)
display(t, y)
end
lua/RungeKutta.lua view on Meta::CPAN
-- www.pjb.com.au --
-- --
-- This module is free software; you can redistribute it and/or --
-- modify it under the same terms as Lua5 itself. --
-- ----------------------------------------------------------------- --
local M = {} -- public interface
M.Version = '1.07'
M.VersionDate = '20aug2010'
-- Example usage:
-- local RK = require 'RungeKutta'
-- RK.rk4()
--------------------- infrastructure ----------------------
local function arr2txt(...) -- neat printing of arrays for debug use
local txt = {}
for e in ... do txt[#txt+1] = string.format('%g',e) end
return table.concat(txt,' ') .. "\n"
end
local function warn(str)
io.stderr:write(str,'\n')
lua/RungeKutta.lua view on Meta::CPAN
--[[
=pod
=head1 NAME
RungeKutta.lua - Integrating Systems of Differential Equations
=head1 SYNOPSIS
local RK = require 'RungeKutta'
function dydt(t, y) -- the derivative function
-- y is the table of the values, dydt the table of the derivatives
-- the table can be an array (1...n), or a dictionary; whichever,
-- the same indices must be used for the return table: dydt
local dydt = {}; ... ; return dydt
end
y = initial_y(); t=0; dt=0.4; -- the initial conditions
-- For automatic timestep adjustment ...
while t < tfinal do
t, dt, y = RK.rk4_auto(y, dydt, t, dt, 0.00001)
lua/test.lua view on Meta::CPAN
-- --
-- This script is free software; you can redistribute it and/or --
-- modify it under the same terms as Lua5 itself. --
-- ----------------------------------------------------------------- --
local Version = '1.0 for Lua5'
local VersionDate = '31jul2010';
local Synopsis = [[
program_name [options] [filenames]
]]
local RK = require 'RungeKutta'
--------------------------- infrastructure -----------------------
local eps = .000000001
function equal(x, y) -- unused here
if #x ~= #y then return false end
local i; for i in pairs(x) do
if math.abs(x[i]-y[i]) > eps then return false end
end
return true
end
-- use Test::Simple tests => 6;
lua/three-body.lua view on Meta::CPAN
-- --
-- This script is free software; you can redistribute it and/or --
-- modify it under the same terms as Lua5 itself. --
-- ----------------------------------------------------------------- --
local Version = '1.0 for Lua5'
local VersionDate = '1aug2010';
local Synopsis = [[
program_name [options] [filenames]
]]
local RK = require 'RungeKutta'
-- my ($maxcols, $maxrows);
-- eval 'require "Term/Size.pm"';
-- if ($@) {
-- $maxcols = `tput cols`;
-- if ($^O eq 'linux') { $maxrows = (`tput lines` + 0);
-- } else { $maxrows = (`tput rows` + 0);
-- }
-- } else {
-- ($maxcols, $maxrows) = &Term::Size::chars(*STDERR);
( run in 0.267 second using v1.01-cache-2.11-cpan-0d8aa00de5b )