Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,26 @@
# Declaration for the sake of euler_table()
create or replace function cooling(x,y) as NULL;
# Euler method assuming cooling/2 is available
create or replace function euler_table(x_start, y_start, x2, h) as table (
with recursive cte as (
select x_start::DOUBLE as x, y_start::DOUBLE as y
union all
select x + h as x,
y + h*cooling(x, y)
from cte
where (x < x2 and x_start < x2) or
(x > x2 and x_start > x2)
)
from cte
);
create or replace function euler(x_start, y_start, x2, h) as (
select last(y order by x) from euler_method(x_start, y_start, x2, h)
);
## Example:
create or replace function cooling(x,y) as
-0.07 * (y - 20);
select h, euler(0,100, 100, h) from unnest([1,2,5,10,20]) _(h);

View file

@ -1,23 +1,9 @@
TR = 20
K = -0.07
func analytic T0 t .
return TR + (T0 - TR) * pow 2.71828 (K * t)
.
ytxt = 95
proc draw_analytic a b .
gcolor 009
gtext 80 ytxt "analytic"
ytxt -= 5
for t = a to b
yp = y
y = analytic 100 t
if t > a : gline t - 1 yp t y
.
.
drawgrid
glinewidth 0.3
gtextsize 3
draw_analytic 0 100
#
func newton_cooling temp .
return K * (temp - TR)
@ -26,14 +12,27 @@ proc draw_euler y t t2 step col .
gcolor col
gtext 80 ytxt "step: " & step
ytxt -= 5
repeat
gpenup
while t <= t2
glineto t y
t += step
yp = y
y += step * newton_cooling y
gline t - step yp t y
until t >= t2
.
.
func analytic T0 t .
return TR + (T0 - TR) * pow 2.71828 (K * t)
.
proc draw_analytic a b .
gcolor 009
gtext 80 ytxt "analytic"
ytxt -= 5
gpenup
for t = a to b
y = analytic 100 t
glineto t y
.
.
draw_euler 100 0 100 10 900
draw_euler 100 0 100 5 555
draw_euler 100 0 100 2 090
draw_analytic 0 100

View file

@ -0,0 +1,33 @@
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

View file

@ -0,0 +1,25 @@
local fmt = require "fmt"
local function euler(f, y, step, finish)
fmt.write(" Step %2d: ", step)
for t = 0, finish, step do
if t % 10 == 0 then fmt.write(" %7.3f", y) end
y += step * f(y)
end
print()
end
local function analytic()
io.write(" Time: ")
for t = 0, 100, 10 do fmt.write(" %7d", t) end
io.write("\nAnalytic: ")
for t = 0, 100, 10 do
fmt.write(" %7.3f", 20 + 80 * math.exp(-0.07 * t))
end
print()
end
local cooling = |temp| -> -0.07 * (temp - 20)
analytic()
for {2, 5, 10} as i do euler(cooling, 100, i, 100) end