diff --git a/lib/Math/Model.pm b/lib/Math/Model.pm index 3f97ec7..fea5a14 100644 --- a/lib/Math/Model.pm +++ b/lib/Math/Model.pm @@ -12,13 +12,14 @@ has %.variables; has %.initials; has @.captures is rw; +has %!inv = %.derivatives.invert; # in Math::Model all variables are accessible by name # in contrast Math::RungeKutta uses vectors, so we need # to define an (arbitrary) ordering # @!deriv-names holds the names of the derivatives in a fixed # order, sod @!deriv-names[$number] turns the number into a name # %!deriv-keying{$name} translates a name into the corresponding index -has @!deriv-names = %.derivatives.keys; +has @!deriv-names = %!inv.keys; has %!deriv-keying = @!deriv-names Z=> 0..Inf; # snapshot of all variables in the current model @@ -52,15 +53,15 @@ method topo-sort(*@a) { method integrate($from = 0, $to = 10, $min-resolution = ($to - $from) / 20) { - my %inv = %.derivatives.invert; for %.derivatives -> $d { die "There must be a variable defined for each derivative, missiing for '$d.key()'" - unless %.variables.exists($d.key) || %inv.exists($d.key); + unless %.variables.exists($d.key) || %!inv.exists($d.key); die "There must be an initial value defined for each derivative target, missing for '$d.value()'" unless %.initials.exists($d.value); } - my %vars = %.variables.pairs.grep: { ! %inv.exists(.key) }; + my %vars = %.variables.pairs.grep: { ! %!inv.exists(.key) }; + say "Vars: %vars.perl()"; %!current-values = %.initials; %!current-values