RosettaCodeData/Task/Euler-method/SequenceL/euler-method.sequencel

26 lines
599 B
Plaintext

import <Utilities/Conversion.sl>;
import <Utilities/Sequence.sl>;
T0 := 100.0;
TR := 20.0;
k := 0.07;
main(args(2)) :=
let
results[i] := euler(newtonCooling, T0, 100, stringToInt(args[i]), 0, "delta_t = " ++ args[i]);
in
delimit(results, '\n');
newtonCooling(t) := -k * (t - TR);
euler: (float -> float) * float * int * int * int * char(1) -> char(1);
euler(f, y, n, h, x, output(1)) :=
let
newOutput := output ++ "\n\t" ++ intToString(x) ++ "\t" ++ floatToString(y, 3);
newY := y + h * f(y);
newX := x + h;
in
output when x > n
else
euler(f, newY, n, h, newX, newOutput);