Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Numerical-integration/Zkl/numerical-integration.zkl
Normal file
24
Task/Numerical-integration/Zkl/numerical-integration.zkl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
fcn integrate(F,f,a,b,steps){
|
||||
h:=(b - a) / steps;
|
||||
h*(0).reduce(steps,'wrap(s,i){ F(f, h*i + a, h) + s },0.0);
|
||||
}
|
||||
|
||||
fcn rectangularLeft(f,x) { f(x) }
|
||||
fcn rectangularMiddle(f,x,h){ f(x+h/2) }
|
||||
fcn rectangularRight(f,x,h) { f(x+h) }
|
||||
fcn trapezium(f,x,h) { (f(x) + f(x+h))/2 }
|
||||
fcn simpson(f,x,h) { (f(x) + 4.0*f(x+h/2) + f(x+h))/6 }
|
||||
|
||||
args:=T( T(fcn(x){ x.pow(3) }, 0.0, 1.0, 10),
|
||||
T(fcn(x){ 1.0 / x }, 1.0, 100.0, 1000),
|
||||
T(fcn(x){ x }, 0.0, 5000.0, 0d5_000_000),
|
||||
T(fcn(x){ x }, 0.0, 6000.0, 0d6_000_000) );
|
||||
fs:=T(rectangularLeft,rectangularMiddle,rectangularRight,
|
||||
trapezium,simpson);
|
||||
names:=fs.pump(List,"name",'+(":"),"%-18s".fmt);
|
||||
|
||||
foreach a in (args){
|
||||
names.zipWith('wrap(nm,f){
|
||||
"%s %f".fmt(nm,integrate(f,a.xplode())).println() }, fs);
|
||||
println();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue