Euler method: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: stray '.' removed, use '×' for clarity) |
||
Line 2,748: | Line 2,748: | ||
for $a, * + $h ... * > $b -> $t { |
for $a, * + $h ... * > $b -> $t { |
||
@t_y[$t] = $y; |
@t_y[$t] = $y; |
||
$y += $h |
$y += $h × f( $t, $y ); |
||
} |
} |
||
@t_y |
|||
} |
} |
||
Line 2,760: | Line 2,760: | ||
sub f ( $time, $temp ) { |
sub f ( $time, $temp ) { |
||
-COOLING_RATE × ( $temp - AMBIENT_TEMP ) |
|||
} |
} |
||
Line 2,771: | Line 2,771: | ||
my $exact = AMBIENT_TEMP + (INITIAL_TEMP - AMBIENT_TEMP) |
my $exact = AMBIENT_TEMP + (INITIAL_TEMP - AMBIENT_TEMP) |
||
× (-COOLING_RATE × $t).exp; |
|||
my $err = sub { @^a.map: { 100 |
my $err = sub { @^a.map: { 100 × ($_ - $exact).abs / $exact } } |
||
my ( $a, $b, $c ) = map { @e[$_][$t] }, 2, 5, 10; |
my ( $a, $b, $c ) = map { @e[$_][$t] }, 2, 5, 10; |
||
say $t.fmt('%4d '), ( $exact, $a, $b, $c )».fmt(' %7.3f'), |
say $t.fmt('%4d '), ( $exact, $a, $b, $c )».fmt(' %7.3f'), |
||
$err |
$err([$a, $b, $c])».fmt(' %7.3f%%'); |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||