45 lines
1.1 KiB
Plaintext
45 lines
1.1 KiB
Plaintext
test: procedure options (main); /* 3 December 2012 */
|
|
|
|
declare (x, y, z) float;
|
|
declare (T0 initial (100), Tr initial (20)) float;
|
|
declare k float initial (0.07);
|
|
declare t fixed binary;
|
|
declare h fixed binary;
|
|
|
|
x, y, z = T0;
|
|
/* Step size is 2 seconds */
|
|
h = 2;
|
|
put skip data (h);
|
|
put skip list (' t By formula', 'By Euler');
|
|
do t = 0 to 100 by 2;
|
|
put skip edit (t, Tr + (T0 - Tr)/exp(k*t), x) (f(3), 2 f(17,10));
|
|
x = x + h*f(t, x);
|
|
end;
|
|
|
|
/* Step size is 5 seconds */
|
|
h = 5;
|
|
put skip data (h);
|
|
put skip list (' t By formula', 'By Euler');
|
|
do t = 0 to 100 by 5;
|
|
put skip edit ( t, Tr + (T0 - Tr)/exp(k*t), y) (f(3), 2 f(17,10));
|
|
y = y + h*f(t, y);
|
|
end;
|
|
|
|
/* Step size is 10 seconds */
|
|
h = 10;
|
|
put skip data (h);
|
|
put skip list (' t By formula', 'By Euler');
|
|
do t = 0 to 100 by 10;
|
|
put skip edit (t, Tr + (T0 - Tr)/exp(k*t), z) (f(3), 2 f(17,10));
|
|
z = z + h*f(t, z);
|
|
end;
|
|
|
|
f: procedure (dummy, T) returns (float);
|
|
declare dummy fixed binary;
|
|
declare T float;
|
|
|
|
return ( -k*(T - Tr) );
|
|
end f;
|
|
|
|
end test;
|