gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/examples
diff options
context:
space:
mode:
authorfrancesco <francesco.bbt@gmail.com>2011年02月28日 23:14:27 +0100
committerfrancesco <francesco.bbt@gmail.com>2011年02月28日 23:14:27 +0100
commit9af3e54b51a4095dd1202ae213a35d4b385f2d69 (patch)
treef0b569c8448c43d803424f5dabde9abf3094a020 /examples
parent8ff6e8c84d8ef10561ad6a889a6333a1a473c21f (diff)
downloadgsl-shell-9af3e54b51a4095dd1202ae213a35d4b385f2d69.tar.gz
Implemented interface to QR decomposition
Only the most important QR-related functions are implemented. Other functions should be added to provide a more complete implementation.
Diffstat (limited to 'examples')
-rw-r--r--examples/qr-lssolve.lua 28
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/qr-lssolve.lua b/examples/qr-lssolve.lua
new file mode 100644
index 00000000..e707f627
--- /dev/null
+++ b/examples/qr-lssolve.lua
@@ -0,0 +1,28 @@
+
+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 = new(n, 1, xsmp)
+ local y = new(n, 1, |i| a*xsmp(i) + b + rnd.gaussian(r, 0.4))
+
+ X = new(n,2, |i,j| j == 1 and a or b * xsmp(i))
+
+ qr = QR(X)
+
+ xls, res = qr:lssolve(y)
+
+ print('Linear fit coefficients: ', tr(xls))
+
+ p = plot()
+ p:addline(xyline(x, X * xls))
+ p:add(xyline(x, y), 'blue', {{'stroke'}, {'marker', size=5}})
+ p.title = 'Linear Fit'
+ p:show()
+
+ return p
+end
+
+echo 'demo1() - examples of linear regression using QR decomposition'
generated by cgit v1.2.3 (git 2.25.1) at 2025年10月02日 07:24:40 +0000

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