Euler method: Difference between revisions

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