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,20 @@
local function integrate(a, b, n, f)
local h = (b - a) / n
local sum = {0, 0, 0, 0, 0}
for i = 1, n do
local x = a + (i - 1) * h
sum[1] += f(x)
sum[2] += f(x + h / 2)
sum[3] += f(x + h)
sum[4] += (f(x) + f(x + h)) / 2
sum[5] += (f(x) + 4 * f(x + h / 2) + f(x + h)) / 6
end
local methods = {"LeftRect ", "MidRect ", "RightRect", "Trapezium", "Simpson "}
for i = 1, 5 do print($"{methods[i]} = {sum[i] * h}") end
print()
end
integrate(0, 1, 100, |v| -> v * v * v)
integrate(1, 100, 1_000, |v| -> 1 / v)
integrate(0, 5_000, 5_000_000, |v| -> v)
integrate(0, 6_000, 6_000_000, |v| -> v)

View file

@ -1,4 +1,4 @@
-- 8 Jun 2025
-- 28 Jul 2025
include Settings
arg digs
if digs = '' then
@ -32,7 +32,7 @@ call Timer
exit
Task:
procedure expose glob.
procedure expose Memo.
arg ff,aa,bb,steps,true
w=Digits()+2
res=LeftRect(ff,aa,bb,steps); diff=res-true
@ -50,59 +50,79 @@ say Left(ff,11) Left(aa '-' bb,w+4) Left('Trapezoid',9) Left(steps,7),
res=Simpson(ff,aa,bb,steps); diff=res-true
say Left(ff,11) Left(aa '-' bb,w+4) Left('Simpson',9) Left(steps,7),
Left(Std(res),w) Left(true,w) Format(diff,2,4,,0)
res=Boole(ff,aa,bb,steps); diff=res-true
say Left(ff,11) Left(aa '-' bb,w+4) Left('Boole',9) Left(steps,7),
Left(Std(res),w) Left(true,w) Format(diff,2,4,,0)
say
return
LeftRect:
procedure expose glob.
procedure expose Memo.
arg ff,aa,bb,steps
h=(bb-aa)/steps; s=0
h=(bb-aa)/steps
s=0
do n = 0 to steps-1
s=s+Eval(ff,aa+n*h)
end
return s*h
MidRect:
procedure expose glob.
procedure expose Memo.
arg ff,aa,bb,steps
h=(bb-aa)/steps; s=0; aa=aa-h/2
h=(bb-aa)/steps; aa=aa-h/2
s=0
do n = 1 to steps
s=s+Eval(ff,aa+n*h)
end
return s*h
RightRect:
procedure expose glob.
procedure expose Memo.
arg ff,aa,bb,steps
h=(bb-aa)/steps; s=0
h=(bb-aa)/steps
s=0
do n = 1 to steps
s=s+Eval(ff,aa+n*h)
end
return s*h
Trapezoid:
procedure expose glob.
procedure expose Memo.
arg ff,aa,bb,steps
h=(bb-aa)/steps; s=0.5*(Eval(ff,aa)+Eval(ff,bb))
h=(bb-aa)/steps
s=0.5*(Eval(ff,aa)+Eval(ff,bb))
do n = 1 to steps-1
s=s+Eval(ff,aa+n*h)
end
return s*h
Simpson:
procedure expose glob.
procedure expose Memo.
arg ff,aa,bb,steps
h=(bb-aa)/steps; s=Eval(ff,aa)+Eval(ff,bb)
h=(bb-aa)/steps
s0=Eval(ff,aa)+Eval(ff,bb); s1=0; s2=0
do n = 1 by 2 to steps-1
s=s+4*Eval(ff,aa+n*h)
s1=s1+Eval(ff,aa+n*h)
end
do n = 2 by 2 to steps-1
s=s+2*Eval(ff,aa+n*h)
do n = 2 by 2 to steps-2
s2=s2+Eval(ff,aa+n*h)
end
return s*h/3
return (s0+4*s1+2*s2)*h/3
include Functions
include Special
include Constants
include Helper
include Abend
Boole:
procedure expose Memo.
arg ff,aa,bb,steps
h=(bb-aa)/steps
s0=7*(Eval(ff,aa)+Eval(ff,bb)); s1=0; s2=0; s3=0
do n = 1 by 2 to steps-1
s1=s1+Eval(ff,aa+n*h)
end
do n = 2 by 4 to steps-2
s2=s2+Eval(ff,aa+n*h)
end
do n = 4 by 4 to steps-4
s3=s3+Eval(ff,aa+n*h)
end
return (s0+32*s1+12*s2+14*s3)*2*h/45
include Math