added interpolation methods for integrals and derivatives - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/examples/interp.lua
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年11月02日 11:03:04 +0100
committerfrancesco-ST <francesco.abbate@st.com>2010年11月02日 11:03:04 +0100
commiteb3acd162831b5af1fbeb59dfc6e5e9bf0f27e45 (patch)
tree6db0339464abf7ed4bb2488cdc7999a2e54a94b0 /examples/interp.lua
parent2ec481f397fa96e11871f077e859182b83e87704 (diff)
downloadgsl-shell-eb3acd162831b5af1fbeb59dfc6e5e9bf0f27e45.tar.gz
added interpolation methods for integrals and derivatives
Diffstat (limited to 'examples/interp.lua')
-rw-r--r--examples/interp.lua 30
1 files changed, 23 insertions, 7 deletions
diff --git a/examples/interp.lua b/examples/interp.lua
index bfc976b2..f733ef63 100644
--- a/examples/interp.lua
+++ b/examples/interp.lua
@@ -1,13 +1,26 @@
function demo1()
+
+ local w = window('v..')
local N = 8
local xsmp = |k| 2*pi*(k-1)/N
- local x, y = new(N, 1, xsmp), new(N, 1, |k| sin(xsmp(k)))
+ local x, y = new(N+1, 1, xsmp), new(N+1, 1, |k| sin(xsmp(k)))
+
+ local function interp_plot(tp)
+ local p = plot(string.format('%s interpolation', tp))
+ p:add(xyline(x, y), 'black', {{'marker', size=5}})
+ local ap = interp(x, y, tp)
+ p:addline(fxline(|x| ap:eval(x), 0, 2*pi), 'blue', {{'dash', 7, 3, 3, 3}})
+ p:addline(fxline(|x| ap:deriv(x), 0, 2*pi))
+ p:add(fxline(cos, 0, 2*pi), 'blue', {{'stroke', width=0.75}, {'dash', 7,3}})
+ print(string.format('%s interp / integral between (%g, %g) = %g', tp,
+ 0, 2*pi, ap:integ(0, 2*pi)))
+ return p
+ end
+
+
local p = plot 'Akima Interpolation'
- p:show()
- p:addline(xyline(x, y))
- local ap = interp(x, y, 'akima')
- p:addline(fxline(|x| ap:eval(x), 0, 2*pi), 'blue', {{'dash', 7, 3, 3, 3}})
- return p, ap
+ w:attach(interp_plot('akima'), '1')
+ w:attach(interp_plot('cspline'), '2')
end
function demo2()
@@ -27,7 +40,10 @@ function demo2()
p:addline(xyline(x, y))
p:add(xyline(x, y), 'black', {{'marker', size= 5}})
local ap = interp(x, y, 'cspline')
- p:addline(fxline(|x| ap:eval(x), 0, x[N]), 'blue', {{'dash', 7, 3, 3, 3}})
+ local a, b = 0, x[N]
+ p:addline(fxline(|x| ap:eval(x), a, b), 'blue', {{'dash', 7, 3, 3, 3}})
+ p:addline(fxline(|x| ap:deriv(x), a, b), 'green')
+ print(string.format('Integral between (%g, %g) = %g', a, b, ap:integ(a, b)))
return p, ap
end
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月25日 22:39:56 +0000

AltStyle によって変換されたページ (->オリジナル) /