Add norm2 method to matrix - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/matrix.lua
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2013年01月27日 17:51:03 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2013年01月28日 09:11:09 +0100
commitf138355b52cf9e50270b9d84e297fcb3463e68d5 (patch)
treef2d7ce528e1c6222119ab3b62d200f6aae47b9cb /matrix.lua
parent20d3f6937b20e8f91606e4f74da75cc53ab5eba8 (diff)
downloadgsl-shell-f138355b52cf9e50270b9d84e297fcb3463e68d5.tar.gz
Add norm2 method to matrix
To compute the sum of squares of a matrix.
Diffstat (limited to 'matrix.lua')
-rw-r--r--matrix.lua 19
1 files changed, 15 insertions, 4 deletions
diff --git a/matrix.lua b/matrix.lua
index 19390dfc..87df4581 100644
--- a/matrix.lua
+++ b/matrix.lua
@@ -509,7 +509,7 @@ local function matrix_complex_unm(a)
return m
end
-local function matrix_norm(m)
+local function matrix_norm2(m)
local r, c = matrix_dim(m)
local tda = m.tda
local ssq, idx = 0, 0
@@ -520,10 +520,14 @@ local function matrix_norm(m)
end
idx = idx + tda
end
- return sqrt(ssq)
+ return ssq
end
-local function matrix_complex_norm(m)
+local function matrix_norm(m)
+ return sqrt(matrix_norm2(m))
+end
+
+local function matrix_complex_norm2(m)
local r, c = matrix_dim(m)
local tda = m.tda
local ssq, idx = 0, 0
@@ -534,7 +538,11 @@ local function matrix_complex_norm(m)
end
idx = idx + 2*tda
end
- return sqrt(ssq)
+ return ssq
+end
+
+local function matrix_complex_norm(m)
+ return sqrt(matrix_complex_norm2(m))
end
complex = {
@@ -543,6 +551,7 @@ complex = {
real = complex_real,
imag = complex_imag,
abs = complex_abs,
+ norm = complex_abs,
norm2 = complex_norm2,
rect = cartesian,
i = 1i,
@@ -662,6 +671,7 @@ local matrix_methods = {
set = matrix_set,
copy = matrix_copy,
norm = matrix_norm,
+ norm2 = matrix_norm2,
slice = matrix_slice,
show = matrix_display_gen(mat_real_get),
}
@@ -727,6 +737,7 @@ local matrix_complex_methods = {
set = matrix_complex_set,
copy = matrix_complex_copy,
norm = matrix_complex_norm,
+ norm2 = matrix_complex_norm2,
slice = matrix_complex_slice,
show = matrix_display_gen(mat_complex_get),
}
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月13日 19:34:42 +0000

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