gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/examples/linfit.lua
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2011年10月24日 13:31:19 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2011年10月24日 13:31:19 +0200
commitc0a06f4256181ad682daf21c4ad30dc74a74447c (patch)
tree2ea2829c86c071a0618bb042af0464d38b13acc5 /examples/linfit.lua
parentbba69adf6f3a6303c38f46f4d0ba4b7cc7828c32 (diff)
downloadgsl-shell-c0a06f4256181ad682daf21c4ad30dc74a74447c.tar.gz
Add demo with linear fit examples
Diffstat (limited to 'examples/linfit.lua')
-rw-r--r--examples/linfit.lua 65
1 files changed, 0 insertions, 65 deletions
diff --git a/examples/linfit.lua b/examples/linfit.lua
deleted file mode 100644
index 69bb266c..00000000
--- a/examples/linfit.lua
+++ /dev/null
@@ -1,65 +0,0 @@
-use 'math'
-use 'iter'
-use 'num'
-
-function demo1()
- local x0, x1, n = 0, 12.5, 32
- local a, b = 0.55, -2.4
- local xsmp = |i| (i-1)/(n-1) * x1
-
- local r = rng()
- local x = matrix.new(n, 1, xsmp)
- local y = matrix.new(n, 1, |i| a*xsmp(i) + b + rnd.gaussian(r, 0.4))
-
- X = matrix.new(n, 2, |i,j| j==1 and 1 or xsmp(i))
-
- c, chisq, cov = linfit(X, y)
-
- print('Linear fit coefficients: ')
-
- local fit = function(x) return c[1]+c[2]*x end
-
- p = graph.fxplot(fit, x0, x1)
- p:add(graph.xyline(x, y), 'blue', {{'stroke'}, {'marker', size=5}})
- p.title = 'Linear Fit'
- p.clip = false
-
- return p
-end
-
-function demo2()
- local order, x0, x1, n = 3, 0.0, 24.0, 96
- local bess = |x| besselJ(order, x)
- local xsmp = |i| x0 + (i-1)/(n-1) * (x1 - x0)
-
- local x = matrix.new(n, 1, xsmp)
- local y = matrix.new(n, 1, |i| besselJ(order, xsmp(i)))
-
- local xnorm = |x| (2*x - x0 - x1) / (x1-x0)
-
- model = function(k, x) return legendreP(k, xnorm(x)) end
-
- legmodel_order = 18
-
- X = matrix.new(n, legmodel_order+1, |i,j| model(j-1, xsmp(i)))
-
- c, chisq = linfit(X, y)
-
- pc = graph.fibars(|i| c[i], 1, #c)
- pc.title = 'Legendre polynomials fit coefficients'
- pc.pad = true
-
- fitleg = function(x)
- return isum(|k| c[k+1] * model(k, x), 0, legmodel_order)
- end
-
- p = graph.fxplot(fitleg, x0, x1)
- p:addline(graph.xyline(x, y), 'blue', {{'marker', size=5}})
- p.title = 'Legendre Polinomial fit of Bessel J3(x)'
- p.clip = false
-
- return p
-end
-
-echo 'demo1() - examples of linear regression of (x, y) data'
-echo 'demo2() - examples of linear regression based on legendre polynomials'
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月30日 03:58:15 +0000

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