Skip to content

Commit

Permalink
There!
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Jun 19, 2010
1 parent 7d0ad48 commit c0f0e1f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
17 changes: 4 additions & 13 deletions lib/Math/Model.pm
Expand Up @@ -61,7 +61,6 @@ method integrate($from = 0, $to = 10, $min-resolution = ($to - $from) / 20) {
} }


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 = %.initials;
%!current-values<time> = $from; %!current-values<time> = $from;
Expand All @@ -75,31 +74,24 @@ method integrate($from = 0, $to = 10, $min-resolution = ($to - $from) / 20) {
%!current-values{$_} = $c.(|self!params-for($c)); %!current-values{$_} = $c.(|self!params-for($c));
} }
} }
say "Deriv names: @!deriv-names.perl()";
say "Start values: %.initials{@!deriv-names}.perl()";
update-current-values($from, %.initials{@!deriv-names}); update-current-values($from, %.initials{@!deriv-names});
say "Start values: %!current-values.perl()";


my @initial = %.initials{@!deriv-names}; my @initial = %.initials{@!deriv-names};


sub derivatives($time, @values) { sub derivatives($time, @values) {
update-current-values($time, @values); update-current-values($time, @values);
my @r; my @r;
for @!deriv-names { for %!inv{@!deriv-names} {
my $v = %.variables{$_}; my $v = %.variables{$_};
if defined $v { @r.push: defined $v
@r.push: $v(|self!params-for($v)); ?? $v(|self!params-for($v))
} else { !! %!current-values{$_};
@r.push: %!current-values{$_};
}
} }
say "Derivatives at time $time: @r.perl()";
@r; @r;
} }


@!time = (); @!time = ();
for @.captures { for @.captures {
say "Initializing record for '$_'";
%!results{$_} = []; %!results{$_} = [];
} }


Expand Down Expand Up @@ -127,7 +119,6 @@ method render-svg($filename) {
my $f = open $filename, :w my $f = open $filename, :w
or die "Can't open file '$filename' for writing: $!"; or die "Can't open file '$filename' for writing: $!";
my @data = map { %!results{$_} }, @.captures; my @data = map { %!results{$_} }, @.captures;
say %!results.perl;
my $svg = SVG::Plot.new( my $svg = SVG::Plot.new(
width => 800, width => 800,
height => 600, height => 600,
Expand Down
2 changes: 1 addition & 1 deletion scratch.pl
Expand Up @@ -19,5 +19,5 @@
captures => <height velocity acceleration>, captures => <height velocity acceleration>,
); );


$m.integrate(:to(2), :min-resolution(0.5)); $m.integrate(:to(5), :min-resolution(0.5));
$m.render-svg('spring.svg'); $m.render-svg('spring.svg');

0 comments on commit c0f0e1f

Please sign in to comment.