Euler method: Difference between revisions
Content added Content deleted
(Added Rust) |
|||
Line 3,128: | Line 3,128: | ||
</pre> |
</pre> |
||
=={{header|VBA}}== |
|||
{{trans|Phix}}<lang vb>Private Sub ivp_euler(f As String, y As Double, step As Integer, end_t As Integer) |
|||
Dim t As Integer |
|||
Debug.Print " Step "; step; ": ", |
|||
Do While t <= end_t |
|||
If t Mod 10 = 0 Then Debug.Print Format(y, "0.000"), |
|||
y = y + step * Application.Run(f, y) |
|||
t = t + step |
|||
Loop |
|||
Debug.Print |
|||
End Sub |
|||
Sub analytic() |
|||
Debug.Print " Time: ", |
|||
For t = 0 To 100 Step 10 |
|||
Debug.Print " "; t, |
|||
Next t |
|||
Debug.Print |
|||
Debug.Print "Analytic: ", |
|||
For t = 0 To 100 Step 10 |
|||
Debug.Print Format(20 + 80 * Exp(-0.07 * t), "0.000"), |
|||
Next t |
|||
Debug.Print |
|||
End Sub |
|||
Private Function cooling(temp As Double) As Double |
|||
cooling = -0.07 * (temp - 20) |
|||
End Function |
|||
Public Sub euler_method() |
|||
Dim r_cooling As String |
|||
r_cooling = "cooling" |
|||
analytic |
|||
ivp_euler r_cooling, 100, 2, 100 |
|||
ivp_euler r_cooling, 100, 5, 100 |
|||
ivp_euler r_cooling, 100, 10, 100 |
|||
End Sub</lang>{{out}} |
|||
<pre> Time: 0 10 20 30 40 50 60 70 80 90 100 |
|||
Analytic: 100,000 59,727 39,728 29,797 24,865 22,416 21,200 20,596 20,296 20,147 20,073 |
|||
Step 2 : 100,000 57,634 37,704 28,328 23,918 21,843 20,867 20,408 20,192 20,090 20,042 |
|||
Step 5 : 100,000 53,800 34,281 26,034 22,549 21,077 20,455 20,192 20,081 20,034 20,014 |
|||
Step 10 : 100,000 44,000 27,200 22,160 20,648 20,194 20,058 20,017 20,005 20,002 20,000 </pre> |
|||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
<lang XPL0>include c:\cxpl\codes; \intrinsic 'code' declarations |
<lang XPL0>include c:\cxpl\codes; \intrinsic 'code' declarations |