34 lines
758 B
Plaintext
34 lines
758 B
Plaintext
include "NSLog.incl"
|
|
|
|
double local fn Cooling( t as double, temp as double )
|
|
return -0.07 * (temp - 20 )
|
|
end fn = 0.0
|
|
|
|
void local fn Euler( y as double, stepSize as int, endTime as double )
|
|
int t = 0
|
|
NSLog( @"\n Step %2d: \b", stepSize )
|
|
while ( t <= endTime )
|
|
if ( t % 10 == 0 ) then NSLog( @" %7.3f \b", y )
|
|
y += stepSize * fn Cooling( t, y )
|
|
t += stepSize
|
|
wend
|
|
end fn
|
|
|
|
void local fn Analytic
|
|
NSLog( @" Time: \b" )
|
|
for int t1 = 0 to 100 step 10
|
|
NSLog( @" %8d\b", t1 )
|
|
next
|
|
NSLog( @"\nAnalytic: \b" )
|
|
for int t2 = 0 to 100 step 10
|
|
NSLog( @"%9.3f\b", 20 + 80 * exp(-0.07 * t2 ) )
|
|
next
|
|
end fn
|
|
|
|
fn Analytic
|
|
fn Euler( 100.0, 2.0, 100.0 )
|
|
fn Euler( 100.0, 5.0, 100.0 )
|
|
fn Euler( 100.0, 10.0, 100.0 )
|
|
|
|
HandleEvents
|