23 lines
533 B
Plaintext
23 lines
533 B
Plaintext
invocable "newton_cooling" # needed to use the 'proc' procedure
|
|
|
|
procedure euler (f, y0, a, b, h)
|
|
t := a
|
|
y := y0
|
|
until (t >= b) do {
|
|
write (right(t, 4) || " " || left(y, 7))
|
|
t +:= h
|
|
y +:= h * (proc(f) (t, y)) # 'proc' applies procedure named in f to (t, y)
|
|
}
|
|
write ("DONE")
|
|
end
|
|
|
|
procedure newton_cooling (time, T)
|
|
return -0.07 * (T - 20)
|
|
end
|
|
|
|
procedure main ()
|
|
# generate data for all three step sizes [2, 5, 10]
|
|
every (step_size := ![2,5,10]) do
|
|
euler ("newton_cooling", 100, 0, 100, step_size)
|
|
end
|