emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 2667d5c: Add new functions for the root mean square


From: Jay Belanger
Subject: [Emacs-diffs] master 2667d5c: Add new functions for the root mean square of a (Calc) vector
Date: Wed, 16 Sep 2015 00:53:52 +0000

branch: master
commit 2667d5c7fbaa3de8103488c7e3779eb768f9d15c
Author: Jay Belanger <address@hidden>
Commit: Jay Belanger <address@hidden>

    Add new functions for the root mean square of a (Calc) vector
    
    * lisp/calc/calc-stats.el (calcFunc-rms, calc-vector-rms):
    New functions.
    * lisp/calc/calc-ext.el (calc-init-extensions): Add keybinding for
    `calc-vector-rms', add autoloads for `calc-vector-rms' and
    `calcFunc-rms'.
    * lisp/calc/calc-map.el (calc-u-oper-keys):  Add entry for
    `calcFunc-rms'.
    * lisp/calc/calc-menu.el (calc-vectors-menu): Add entry for
    `calc-vector-rms'.
    * doc/misc/calc.texi (Single-Variable Statistics): Document the rms
    command.
---
 doc/misc/calc.texi     |   10 +++++++---
 lisp/calc/calc-ext.el  |    7 ++++---
 lisp/calc/calc-map.el  |    1 +
 lisp/calc/calc-menu.el |    7 +++++++
 lisp/calc/calc-stat.el |   11 +++++++++++
 5 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi
index 034f42b..06e476d 100644
--- a/doc/misc/calc.texi
+++ b/doc/misc/calc.texi
@@ -20738,9 +20738,12 @@ mean, then repeating until the two values converge.
 $$ a_{i+1} = { a_i + b_i \over 2 } , \qquad b_{i+1} = \sqrt{a_i b_i} $$
 @end tex
 
address@hidden @cindex Root-mean-square
address@hidden Another commonly used mean, the RMS (root-mean-square), can be 
computed
address@hidden for a vector of numbers simply by using the @kbd{A} command.
address@hidden u R
address@hidden Root-mean-square
address@hidden rms
+Another commonly used mean, the RMS (root-mean-square), can be computed
+for a vector of numbers by using the @kbd{u R}
+(@code{calc-vector-rms}) address@hidden
 
 @kindex u S
 @pindex calc-vector-sdev
@@ -36503,6 +36506,7 @@ keystrokes are not listed in this summary.
 @r{      v@:    H u M   @:             @:    19  @:vmedian@:(v)}
 @r{      v@:  I H u M   @:             @:    19  @:vhmean@:(v)}
 @r{      v@:      u N   @:             @:    19  @:vmin@:(v)}
address@hidden      v@:      u R   @:             @:        @:rms@:(v)}
 @r{      v@:      u S   @:             @:    19  @:vsdev@:(v)}
 @r{      v@:    I u S   @:             @:    19  @:vpsdev@:(v)}
 @r{      v@:    H u S   @:             @:    19  @:vvar@:(v)}
diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el
index cb6ab6f..27898fd 100644
--- a/lisp/calc/calc-ext.el
+++ b/lisp/calc/calc-ext.el
@@ -574,6 +574,7 @@
   (define-key calc-mode-map "uG" 'calc-vector-geometric-mean)
   (define-key calc-mode-map "uM" 'calc-vector-mean)
   (define-key calc-mode-map "uN" 'calc-vector-min)
+  (define-key calc-mode-map "uR" 'calc-vector-rms)
   (define-key calc-mode-map "uS" 'calc-vector-sdev)
   (define-key calc-mode-map "uU" 'calc-undo)
   (define-key calc-mode-map "uX" 'calc-vector-max)
@@ -932,7 +933,7 @@ calc-preserve-point calc-replace-selections 
calc-replace-sub-formula
 calc-roll-down-with-selections calc-roll-up-with-selections
 calc-sel-error)
 
- ("calc-stat" calc-vector-op calcFunc-agmean
+ ("calc-stat" calc-vector-op calcFunc-agmean calcFunc-rms
 calcFunc-vcorr calcFunc-vcount calcFunc-vcov calcFunc-vflat
 calcFunc-vgmean calcFunc-vhmean calcFunc-vmax calcFunc-vmean
 calcFunc-vmeane calcFunc-vmedian calcFunc-vmin calcFunc-vpcov
@@ -1147,8 +1148,8 @@ calc-vector-covariance calc-vector-geometric-mean
 calc-vector-harmonic-mean calc-vector-max calc-vector-mean
 calc-vector-mean-error calc-vector-median calc-vector-min
 calc-vector-pop-covariance calc-vector-pop-sdev
-calc-vector-pop-variance calc-vector-product calc-vector-sdev
-calc-vector-sum calc-vector-variance)
+calc-vector-pop-variance calc-vector-product calc-vector-rms
+calc-vector-sdev calc-vector-sum calc-vector-variance)
 
  ("calc-store" calc-assign calc-copy-special-constant
 calc-copy-variable calc-declare-variable
diff --git a/lisp/calc/calc-map.el b/lisp/calc/calc-map.el
index 3b5949c..d2c9da8 100644
--- a/lisp/calc/calc-map.el
+++ b/lisp/calc/calc-map.el
@@ -417,6 +417,7 @@
                                ( ?G 1 calcFunc-vgmean )
                                ( ?M 1 calcFunc-vmean )
                                ( ?N 1 calcFunc-vmin )
+                                ( ?R 1 calcFunc-rms )
                                ( ?S 1 calcFunc-vsdev )
                                ( ?X 1 calcFunc-vmax ) )
                              ( ( ?C 2 calcFunc-vpcov )
diff --git a/lisp/calc/calc-menu.el b/lisp/calc/calc-menu.el
index 4408687..8610090 100644
--- a/lisp/calc/calc-menu.el
+++ b/lisp/calc/calc-menu.el
@@ -863,6 +863,13 @@
               :keys "I u M"
               :active (>= (calc-stack-size) 1)
               :help "The average (arithmetic mean) of the data values as an 
error form"]
+              ["rms(1:)"
+               (progn
+                 (require 'calc-stat)
+                 (call-interactively 'calc-vector-rms))
+               :keys "u R"
+               :active (>= (calc-stack-size) 1)
+               :help "The root mean square of the data values"]
               ["sdev(1:)"
                (progn
                  (require 'calc-stat)
diff --git a/lisp/calc/calc-stat.el b/lisp/calc/calc-stat.el
index cf0b3ea..a797db2 100644
--- a/lisp/calc/calc-stat.el
+++ b/lisp/calc/calc-stat.el
@@ -71,6 +71,11 @@
         (calc-vector-op "meae" 'calcFunc-vmeane arg)
        (calc-vector-op "mean" 'calcFunc-vmean arg)))))
 
+(defun calc-vector-rms (arg)
+  (interactive "P")
+  (calc-slow-wrapper
+   (calc-vector-op "rms" 'calcFunc-rms arg)))
+
 (defun calc-vector-mean-error (arg)
   (interactive "P")
   (calc-invert-func)
@@ -318,6 +323,12 @@
                          suminvsqrwts))
            (math-div (calcFunc-reduce '(var add var-add) means) len)))))))
 
+(defun calcFunc-rms (a)
+  "Return the root-mean-square of the vector A."
+  (math-sqrt
+   (calcFunc-vmean
+    (calcFunc-map '(var abssqr var-abssqr) a))))
+
 (defun math-fix-int-intv (x)
   (if (math-floatp x)
       x



reply via email to

[Prev in Thread] Current Thread [Next in Thread]