Euler method: Difference between revisions

Add Nimrod
(Add Nimrod)
Line 1,238:
 
The result is displayed on the indicator.
 
=={{header|Nimrod}}==
<lang nimrod>import strutils
 
proc euler(f: proc (x,y: float): float; y0, a, b, h: float) =
var (t,y) = (a,y0)
while t < b:
echo formatFloat(t, ffDecimal, 3), " ", formatFloat(y, ffDecimal, 3)
t += h
y += h * f(t,y)
 
proc newtoncooling(time, temp): float =
-0.07 * (temp - 20)
 
euler(newtoncooling, 100.0, 0.0, 100.0, 10.0)</lang>
Output:
<pre>0.000 100.000
10.000 44.000
20.000 27.200
30.000 22.160
40.000 20.648
50.000 20.194
60.000 20.058
70.000 20.017
80.000 20.005
90.000 20.002</pre>
 
=={{header|Objeck}}==
Anonymous user