Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,52 +0,0 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Generic_Elementary_Functions;
procedure RungeKutta is
type Floaty is digits 15;
type Floaty_Array is array (Natural range <>) of Floaty;
package FIO is new Ada.Text_IO.Float_IO(Floaty); use FIO;
type Derivative is access function(t, y : Floaty) return Floaty;
package Math is new Ada.Numerics.Generic_Elementary_Functions (Floaty);
function calc_err (t, calc : Floaty) return Floaty;
procedure Runge (yp_func : Derivative; t, y : in out Floaty_Array;
dt : Floaty) is
dy1, dy2, dy3, dy4 : Floaty;
begin
for n in t'First .. t'Last-1 loop
dy1 := dt * yp_func(t(n), y(n));
dy2 := dt * yp_func(t(n) + dt / 2.0, y(n) + dy1 / 2.0);
dy3 := dt * yp_func(t(n) + dt / 2.0, y(n) + dy2 / 2.0);
dy4 := dt * yp_func(t(n) + dt, y(n) + dy3);
t(n+1) := t(n) + dt;
y(n+1) := y(n) + (dy1 + 2.0 * (dy2 + dy3) + dy4) / 6.0;
end loop;
end Runge;
procedure Print (t, y : Floaty_Array; modnum : Positive) is begin
for i in t'Range loop
if i mod modnum = 0 then
Put("y("); Put (t(i), Exp=>0, Fore=>0, Aft=>1);
Put(") = "); Put (y(i), Exp=>0, Fore=>0, Aft=>8);
Put(" Error:"); Put (calc_err(t(i),y(i)), Aft=>5);
New_Line;
end if;
end loop;
end Print;
function yprime (t, y : Floaty) return Floaty is begin
return t * Math.Sqrt (y);
end yprime;
function calc_err (t, calc : Floaty) return Floaty is
actual : constant Floaty := (t**2 + 4.0)**2 / 16.0;
begin return abs(actual-calc);
end calc_err;
dt : constant Floaty := 0.10;
N : constant Positive := 100;
t_arr, y_arr : Floaty_Array(0 .. N);
begin
t_arr(0) := 0.0;
y_arr(0) := 1.0;
Runge (yprime'Access, t_arr, y_arr, dt);
Print (t_arr, y_arr, 10);
end RungeKutta;

View file

@ -1,36 +0,0 @@
function Runge-Kutta (${function:F}, ${function:y}, $y0, $t0, $dt, $tEnd) {
function RK ($tn,$yn) {
$y1 = $dt*(F -t $tn -y $yn)
$y2 = $dt*(F -t ($tn + (1/2)*$dt) -y ($yn + (1/2)*$y1))
$y3 = $dt*(F -t ($tn + (1/2)*$dt) -y ($yn + (1/2)*$y2))
$y4 = $dt*(F -t ($tn + $dt) -y ($yn + $y3))
$yn + (1/6)*($y1 + 2*$y2 + 2*$y3 + $y4)
}
function time ($t0, $dt, $tEnd) {
$end = [MATH]::Floor(($tEnd - $t0)/$dt)
foreach ($_ in 0..$end) { $_*$dt + $t0 }
}
$time, $yn, $t = (time $t0 $dt $tEnd), $y0, 0
foreach ($tn in $time) {
if($t -eq $tn) {
[pscustomobject]@{
t = "$tn"
y = "$yn"
error = "$([MATH]::abs($yn - (y $tn)))"
}
$t += 1
}
$yn = RK $tn $yn
}
}
function F ($t,$y) {
$t * [MATH]::Sqrt($y)
}
function y ($t) {
(1/16) * [MATH]::Pow($t*$t + 4,2)
}
$y0 = 1
$t0 = 0
$dt = 0.1
$tEnd = 10
Runge-Kutta F y $y0 $t0 $dt $tEnd

View file

@ -1,51 +1,51 @@
-- 28 Jul 2025
include Settings
-- 18 Sep 2025
include Setting
numeric digits 16
say "RUNGE-KUTTA METHOD FOR ODE y'=x*SqRt(y)"
say "RUNGE-KUTTA METHOD FOR ODE y'=x*Sqrt(y)"
say version
say
numeric digits 9
call Task 0,10,1/10,1
numeric digits 16
call Task 0,10,1/10,1
numeric digits 9
call Task 0,10,1/20,1
numeric digits 16
call Task 0,10,1/20,1
call Timer
exit
Task:
-- Runge-Kutta method
procedure expose Memo.
arg x0,xn,dx,y0
say 'From' x0 'to' xn 'step' dx
say ' x Calc y True y Abs err Rel err'
x=x0; y=y0
say 'From' x0 'to' xn 'step' dx 'with' Digits() 'digits'
say ' x Calc y True y Abs error Rel error'
call Show x,y
do until x >= xn
dy1=dx*DyDx(x,y)
dy2=dx*DyDx(x+dx/2,y+dy1/2)
dy3=dx*DyDx(x+dx/2,y+dy2/2)
dy4=dx*DyDx(x+dx,y+dy3)
x=x+dx; y=y+(dy1+2*dy2+2*dy3+dy4)/6
do until x > xn
if Integer(x) then
call Show x,y
dy1=dx*Dy(x,y)
dy2=dx*Dy(x+dx/2,y+dy1/2)
dy3=dx*Dy(x+dx/2,y+dy2/2)
dy4=dx*Dy(x+dx,y+dy3)
x+=dx; y+=(dy1+2*dy2+2*dy3+dy4)/6
end
say
return
DyDx:
Show:
-- Display a line
procedure
arg xx,yy
yt=True(xx)
say Format(xx,2,0) Format(yy,3,7) Format(True(xx),3,7),
Left(Std(Abs(yy-True(xx))),10) Left(Std(Abs(yy/True(xx)-1)),10)
return
Dy:
-- Differential equation
procedure expose Memo.
arg xx,yy
return xx*SqRt(yy)
True:
-- Real solution
procedure
arg xx
return (xx**2+4)**2/16
Show:
arg xx,yy
say Format(xx,2,0) Format(yy,3,8) Format(True(xx),3,8),
Left(Std(Abs(yy-True(xx))),10) Left(Std(Abs(yy/True(xx)-1)),10)
return
include Math