Euler method: Difference between revisions
Content added Content deleted
(Add Factor example) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 62: | Line 62: | ||
A reference solution ([[#Common Lisp|Common Lisp]]) can be seen below. We see that bigger step sizes lead to reduced approximation accuracy. |
A reference solution ([[#Common Lisp|Common Lisp]]) can be seen below. We see that bigger step sizes lead to reduced approximation accuracy. |
||
[[Image:Euler_Method_Newton_Cooling.png|center|750px]] |
[[Image:Euler_Method_Newton_Cooling.png|center|750px]] |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>F euler(f, y0, a, b, h) |
|||
V t = a |
|||
V y = y0 |
|||
L t <= b |
|||
print(‘#2.3 #2.3’.format(t, y)) |
|||
t += h |
|||
y += h * f(t, y) |
|||
V newtoncooling = (time, temp) -> -0.07 * (temp - 20) |
|||
euler(newtoncooling, 100.0, 0.0, 100.0, 10.0)</lang> |
|||
{{out}} |
|||
<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 |
|||
100.000 20.000 |
|||
</pre> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
Line 2,369: | Line 2,397: | ||
80.000 20.005 |
80.000 20.005 |
||
90.000 20.002 |
90.000 20.002 |
||
100.000 20.000 |
|||
</pre> |
</pre> |
||