local fmt = require "fmt" local function euler(f, y, step, finish) fmt.write(" Step %2d: ", step) for t = 0, finish, step do if t % 10 == 0 then fmt.write(" %7.3f", y) end y += step * f(y) end print() end local function analytic() io.write(" Time: ") for t = 0, 100, 10 do fmt.write(" %7d", t) end io.write("\nAnalytic: ") for t = 0, 100, 10 do fmt.write(" %7.3f", 20 + 80 * math.exp(-0.07 * t)) end print() end local cooling = |temp| -> -0.07 * (temp - 20) analytic() for {2, 5, 10} as i do euler(cooling, 100, i, 100) end