Euler method: Difference between revisions
Content added Content deleted
(Added various BASIC dialects (Applesoft BASIC, BASIC256, Chipmunk Basic, Gambas, GW-BASIC, MSX Basic, QBasic, True BASIC and Yabasic)) |
|||
Line 383: | Line 383: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
==={{header|Applesoft BASIC}}=== |
|||
{{trans|GW-BASIC}} |
|||
<syntaxhighlight lang="qbasic">100 HOME |
|||
110 PRINT "Time "; |
|||
120 FOR S = 0 TO 100.1 STEP 10 |
|||
130 PRINT S; " "; |
|||
140 NEXT S |
|||
150 PRINT |
|||
160 PRINT "Dif eq "; |
|||
170 FOR S = 0 TO 100.1 STEP 10 |
|||
180 LET T = 20+(100-20)*EXP(-.07*S) |
|||
190 PRINT LEFT$(STR$(T),5); " "; |
|||
200 NEXT S |
|||
210 PRINT |
|||
220 LET P = 2 : GOSUB 260 |
|||
230 LET P = 5 : GOSUB 260 |
|||
240 LET P = 10 : GOSUB 260 |
|||
250 END |
|||
260 REM Euler(paso) |
|||
270 LET S = 0 |
|||
280 LET T = 100 |
|||
290 PRINT "Step ";P; " "; |
|||
300 FOR S = 0 TO 100 STEP P |
|||
310 IF S - (S/10) * 10 = 0 THEN PRINT LEFT$(STR$(T),5); " "; |
|||
320 LET T = T+(P)*(-.07*(T-20)) |
|||
330 IF S > 100 THEN GOTO 350 |
|||
340 NEXT S |
|||
350 PRINT |
|||
360 RETURN</syntaxhighlight> |
|||
==={{header|BASIC256}}=== |
|||
{{trans|XPL0}} |
|||
<syntaxhighlight lang="vbnet">print "Time "; |
|||
tiempo = 0.0 |
|||
while tiempo <= 100.1 |
|||
print rjust(string(tiempo), 5); " "; |
|||
tiempo += 10.0 |
|||
end while |
|||
print |
|||
print "Dif eq "; |
|||
tiempo = 0.0 |
|||
while tiempo <= 100.1 |
|||
temperatura = 20.0 + (100.0-20.0) * exp(-0.07*tiempo) |
|||
print rjust(left(string(temperatura), 5), 5); " "; |
|||
tiempo += 10.0 |
|||
end while |
|||
print |
|||
call Euler(2) |
|||
call Euler(5) |
|||
call Euler(10) |
|||
end |
|||
subroutine Euler(paso) |
|||
tiempo = 0 |
|||
temperatura = 100.0 |
|||
print "Step "; rjust(string(paso), 2); " "; |
|||
while tiempo <= 100 |
|||
if (tiempo mod 10) = 0 then print rjust(left(string(temperatura), 5), 5); " "; |
|||
temperatura += float(paso) * (-0.07*(temperatura-20.0)) |
|||
tiempo += paso |
|||
end while |
|||
print |
|||
end subroutine</syntaxhighlight> |
|||
==={{header|BBC BASIC}}=== |
==={{header|BBC BASIC}}=== |
||
<syntaxhighlight lang="bbcbasic"> PROCeuler("-0.07*(y-20)", 100, 0, 100, 2) |
<syntaxhighlight lang="bbcbasic"> PROCeuler("-0.07*(y-20)", 100, 0, 100, 2) |
||
Line 420: | Line 487: | ||
100.000 20.000 |
100.000 20.000 |
||
</pre> |
</pre> |
||
==={{header|Chipmunk Basic}}=== |
|||
{{works with|Chipmunk Basic|3.6.4}} |
|||
Same code as [[#GW-BASIC|GW-BASIC]] |
|||
==={{header|Craft Basic}}=== |
==={{header|Craft Basic}}=== |
||
Line 556: | Line 627: | ||
</pre> |
</pre> |
||
==={{header|Gambas}}=== |
|||
{{trans|XPL0}} |
|||
<syntaxhighlight lang="vbnet">Public Sub Main() |
|||
Dim tiempo As Float, temperatura As Float |
|||
Print "Time "; |
|||
tiempo = 0.0 |
|||
While tiempo <= 100.1 |
|||
Print Format$(tiempo, "#######"); |
|||
tiempo += 10.0 |
|||
Wend |
|||
Print |
|||
Print "Dif eq "; |
|||
tiempo = 0.0 |
|||
While tiempo <= 100.1 |
|||
temperatura = 20.0 + (100.0 - 20.0) * Exp(-0.07 * tiempo) |
|||
Print Format$(temperatura, "####.#0"); |
|||
tiempo += 10.0 |
|||
Wend |
|||
Print |
|||
Euler(2) |
|||
Euler(5) |
|||
Euler(10) |
|||
End |
|||
Public Sub Euler(paso As Integer) |
|||
Dim tiempo As Integer = 0 |
|||
Dim temperatura As Float = 100.0 |
|||
Print "Step "; Format$(paso, "##"); " "; |
|||
Do While tiempo <= 100 |
|||
If (tiempo Mod 10) = 0 Then Print Format$(temperatura, "####.#0"); |
|||
temperatura += (paso) * (-0.07 * (temperatura - 20.0)) |
|||
tiempo += paso |
|||
Loop |
|||
Print |
|||
End Sub</syntaxhighlight> |
|||
==={{header|GW-BASIC}}=== |
|||
{{trans|XPL0}} |
|||
{{works with|PC-BASIC|any}} |
|||
{{works with|BASICA}} |
|||
{{works with|QBasic}} |
|||
{{works with|MSX BASIC}} |
|||
<syntaxhighlight lang="qbasic">100 CLS |
|||
110 PRINT "Time "; |
|||
120 FOR TIEMPO = 0 TO 100.1 STEP 10 |
|||
130 PRINT USING " ###";TIEMPO; |
|||
140 NEXT TIEMPO |
|||
150 PRINT |
|||
160 PRINT "Dif eq "; |
|||
170 FOR TIEMPO = 0 TO 100.1 STEP 10 |
|||
180 TEMPERATURA = 20+(100-20)*EXP(-.07*TIEMPO) |
|||
190 PRINT USING "###.##";TEMPERATURA; |
|||
200 NEXT TIEMPO |
|||
210 PRINT |
|||
220 PASO = 2 : GOSUB 260 |
|||
230 PASO = 5 : GOSUB 260 |
|||
240 PASO = 10 : GOSUB 260 |
|||
250 END |
|||
260 REM Euler(paso) |
|||
270 TIEMPO = 0 |
|||
280 TEMPERATURA = 100 |
|||
290 PRINT USING "Step ## ";PASO; |
|||
300 FOR TIEMPO = 0 TO 100 STEP PASO |
|||
310 IF (TIEMPO MOD 10) = 0 THEN PRINT USING "###.##";TEMPERATURA; |
|||
320 TEMPERATURA = TEMPERATURA+(PASO)*(-.07*(TEMPERATURA-20)) |
|||
330 IF TIEMPO > 100 THEN EXIT FOR |
|||
340 NEXT TIEMPO |
|||
350 PRINT |
|||
360 RETURN</syntaxhighlight> |
|||
==={{header|MSX Basic}}=== |
|||
{{works with|MSX BASIC|any}} |
|||
Same code as [[#GW-BASIC|GW-BASIC]] |
|||
==={{header|QBasic}}=== |
|||
{{trans|XPL0}} |
|||
{{works with|QBasic|1.1}} |
|||
{{works with|QuickBasic|4.5}} |
|||
<syntaxhighlight lang="qbasic">DECLARE SUB Euler (paso AS INTEGER) |
|||
CLS |
|||
PRINT "Time "; |
|||
tiempo = 0! |
|||
WHILE tiempo <= 100.1 |
|||
PRINT USING "######"; tiempo; |
|||
tiempo = tiempo + 10! |
|||
WEND |
|||
PRINT |
|||
PRINT "Dif eq "; |
|||
tiempo = 0! |
|||
WHILE tiempo <= 100.1 |
|||
temperatura = 20! + (100! - 20!) * EXP(-.07 * tiempo) |
|||
PRINT USING "###.##"; temperatura; |
|||
tiempo = tiempo + 10! |
|||
WEND |
|||
PRINT |
|||
Euler (2) |
|||
Euler (5) |
|||
Euler (10) |
|||
END |
|||
SUB Euler (paso AS INTEGER) |
|||
tiempo = 0 |
|||
temperatura = 100! |
|||
PRINT USING "Step ## "; paso; |
|||
DO WHILE tiempo <= 100 |
|||
IF (tiempo MOD 10) = 0 THEN PRINT USING "###.##"; temperatura; |
|||
temperatura = temperatura + paso * (-.07 * (temperatura - 20!)) |
|||
tiempo = tiempo + paso |
|||
LOOP |
|||
PRINT |
|||
END SUB</syntaxhighlight> |
|||
==={{header|Run BASIC}}=== |
==={{header|Run BASIC}}=== |
||
Line 592: | Line 788: | ||
70 20.017496 |
70 20.017496 |
||
80 20.0052488</pre> |
80 20.0052488</pre> |
||
==={{header|True BASIC}}=== |
|||
{{trans|QBasic}} |
|||
<syntaxhighlight lang="qbasic">SUB euler (paso) |
|||
LET tiempo = 0 |
|||
LET temperatura = 100 |
|||
PRINT USING "Step ## ": paso; |
|||
DO WHILE tiempo <= 100 |
|||
IF (REMAINDER(tiempo,10)) = 0 THEN PRINT USING "###.##": temperatura; |
|||
LET temperatura = temperatura+paso*(-.07*(temperatura-20)) |
|||
LET tiempo = tiempo+paso |
|||
LOOP |
|||
PRINT |
|||
END SUB |
|||
PRINT "Time "; |
|||
LET tiempo = 0 |
|||
DO WHILE tiempo <= 100.1 |
|||
PRINT USING "######": tiempo; |
|||
LET tiempo = tiempo+10 |
|||
LOOP |
|||
PRINT |
|||
PRINT "Dif eq "; |
|||
LET tiempo = 0 |
|||
DO WHILE tiempo <= 100.1 |
|||
LET temperatura = 20+(100-20)*EXP(-.07*tiempo) |
|||
PRINT USING "###.##": temperatura; |
|||
LET tiempo = tiempo+10 |
|||
LOOP |
|||
PRINT |
|||
CALL Euler (2) |
|||
CALL Euler (5) |
|||
CALL Euler (10) |
|||
END</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as QBasic entry.</pre> |
|||
==={{header|Yabasic}}=== |
|||
{{trans|XPL0}} |
|||
<syntaxhighlight lang="vbnet">print "Time "; |
|||
tiempo = 0.0 |
|||
while tiempo <= 100.1 |
|||
print tiempo using "#######"; |
|||
tiempo = tiempo + 10.0 |
|||
wend |
|||
print |
|||
print "Dif eq "; |
|||
tiempo = 0.0 |
|||
while tiempo <= 100.1 |
|||
temperatura = 20.0 + (100.0-20.0) * exp(-0.07*tiempo) |
|||
print temperatura using "####.##"; |
|||
tiempo = tiempo + 10.0 |
|||
wend |
|||
print |
|||
Euler_(2) |
|||
Euler_(5) |
|||
Euler_(10) |
|||
end |
|||
sub Euler_(paso) |
|||
local tiempo, temperatura |
|||
tiempo = 0 |
|||
temperatura = 100.0 |
|||
print "Step ", paso using "##", " "; |
|||
while tiempo <= 100 |
|||
if mod(tiempo, 10) = 0 print temperatura using "####.##"; |
|||
temperatura = temperatura + (paso) * (-0.07*(temperatura-20.0)) |
|||
tiempo = tiempo + paso |
|||
end while |
|||
print |
|||
end sub</syntaxhighlight> |
|||
=={{header|C}}== |
=={{header|C}}== |