From: Jay Belanger Date: Wed, 16 Sep 2015 00:53:06 +0000 (-0500) Subject: Add new functions for the root mean square of a (Calc) vector X-Git-Tag: emacs-25.0.90~1224^2~109 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2667d5c7fbaa3de8103488c7e3779eb768f9d15c;p=emacs.git 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. --- diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi index 034f42b1a16..06e476d9313 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 -@c @cindex Root-mean-square -@c Another commonly used mean, the RMS (root-mean-square), can be computed -@c for a vector of numbers simply by using the @kbd{A} command. +@kindex u R +@cindex Root-mean-square +@tindex 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}) [@code{rms}]command. @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)} +@r{ 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 cb6ab6f8ecc..27898fd9c97 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 3b5949c274b..d2c9da86a6f 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 44086872dd0..8610090c5d1 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 cf0b3ea4a12..a797db2e67d 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