RosettaCodeData/Task/Euler-method/Futhark/euler-method.futhark

16 lines
474 B
Text
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
let analytic(t0: f64) (time: f64): f64 =
2017-09-23 10:01:46 +02:00
20.0 + (t0 - 20.0) * f64.exp(-0.07*time)
2016-12-05 23:44:36 +01:00
2019-09-12 10:33:56 -07:00
let cooling(_time: f64) (temperature: f64): f64 =
2016-12-05 23:44:36 +01:00
-0.07 * (temperature-20.0)
2019-09-12 10:33:56 -07:00
let main(t0: f64) (a: f64) (b: f64) (h: f64): []f64 =
let steps = i32.f64 ((b-a)/h)
2016-12-05 23:44:36 +01:00
let temps = replicate steps 0.0
2019-09-12 10:33:56 -07:00
let (_,temps) = loop (t,temps)=(t0,temps) for i < steps do
let x = a + f64.i32 i * h
2017-09-23 10:01:46 +02:00
let temps[i] = f64.abs(t-analytic t0 x)
2016-12-05 23:44:36 +01:00
in (t + h * cooling x t,
temps)
in temps