Euler method: Difference between revisions

2,471 bytes added ,  11 years ago
REXX added
(REXX added)
Line 1,464:
 
See also [[Runge-Kutta method#Racket]]
 
=={{header|REXX}}==
{{trans|PLI}}
<lang rexx>/* REXX ***************************************************************
* 24.05.2013 Walter Pachl translated from PL/I
**********************************************************************/
Numeric Digits 100
T0=100
Tr=20
k=0.07
 
h=2
x=t0
Call head
do t=0 to 100 by 2
Select
When t<=4 | t>=96 Then
call o x
When t=8 Then
Say '...'
Otherwise
Nop
End
x=x+h*f(x)
end
 
h=5
y=t0
Call head
do t=0 to 100 by 5
call o y
y=y+h*f(y)
end
 
h=10
z=t0
Call head
do t=0 to 100 by 10
call o z
z=z+h*f(z)
end
Exit
 
f: procedure Expose k Tr
Parse Arg t
return -k*(T-Tr)
 
head:
Say 'h='h
Say ' t By formula By Euler'
Return
 
o:
Parse Arg v
Say right(t,3) format(Tr+(T0-Tr)/exp(k*t),5,10) format(v,5,10)
Return </lang>
Output:
<pre>
h=2
t By formula By Euler
0 100.0000000000 100.0000000000
2 89.5486587628 88.8000000000
4 80.4626994233 79.1680000000
...
96 20.0965230572 20.0574137147
98 20.0839131147 20.0493757946
100 20.0729505571 20.0424631834
h=5
t By formula By Euler
0 100.0000000000 100.0000000000
5 76.3750471216 72.0000000000
10 59.7268242534 53.8000000000
15 47.9950199099 41.9700000000
20 39.7277571000 34.2805000000
25 33.9019154664 29.2823250000
30 29.7965142633 26.0335112500
35 26.9034869314 23.9217823125
40 24.8648050015 22.5491585031
45 23.4281701466 21.6569530270
50 22.4157906708 21.0770194676
55 21.7023789162 20.7000626539
60 21.1996461464 20.4550407250
65 20.8453763508 20.2957764713
70 20.5957266443 20.1922547063
75 20.4198014729 20.1249655591
80 20.2958290978 20.0812276134
85 20.2084672415 20.0527979487
90 20.1469043822 20.0343186667
95 20.1035217684 20.0223071333
100 20.0729505571 20.0144996367
h=10
t By formula By Euler
0 100.0000000000 100.0000000000
10 59.7268242534 44.0000000000
20 39.7277571000 27.2000000000
30 29.7965142633 22.1600000000
40 24.8648050015 20.6480000000
50 22.4157906708 20.1944000000
60 21.1996461464 20.0583200000
70 20.5957266443 20.0174960000
80 20.2958290978 20.0052488000
90 20.1469043822 20.0015746400
100 20.0729505571 20.0004723920</pre>
 
=={{header|Ruby}}==
2,295

edits