aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJay Belanger2010-05-15 23:43:09 -0500
committerJay Belanger2010-05-15 23:43:09 -0500
commit597517ef8dc589e3b920a0f5bcdf55f9f6cde644 (patch)
tree58bec545b37f91bef730a8e5f21130a5d74c64c1 /lisp
parenteba62f7a5950e77d207ea233a10597f2c9639b0b (diff)
downloademacs-597517ef8dc589e3b920a0f5bcdf55f9f6cde644.tar.gz
emacs-597517ef8dc589e3b920a0f5bcdf55f9f6cde644.zip
calc-vec.el (calc-histogram):
(calcFunc-histogram): Allow vectors as inputs. (math-vector-avg): New function. calc.texi (Manipulating Vectors): Mention that vectors can be used to determine bins for `calc-histogram'.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/calc/README2
-rw-r--r--lisp/calc/calc-vec.el71
3 files changed, 58 insertions, 19 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 27574c31d55..23338834d63 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
12010-05-16 Jay Belanger <jay.p.belanger@gmail.com> 12010-05-16 Jay Belanger <jay.p.belanger@gmail.com>
2 2
3 * calc/calc-vec.el (calc-histogram):
4 (calcFunc-histogram): Allow vectors as inputs.
5 (math-vector-avg): New function.
6
3 * calc/calc-ext.el (math-group-float): Have the number of digits 7 * calc/calc-ext.el (math-group-float): Have the number of digits
4 being grouped depend on the radix (Bug#6189). 8 being grouped depend on the radix (Bug#6189).
5 9
diff --git a/lisp/calc/README b/lisp/calc/README
index 3e3acaebb27..4b32ada63ad 100644
--- a/lisp/calc/README
+++ b/lisp/calc/README
@@ -74,6 +74,8 @@ Summary of changes to "Calc"
74 74
75Emacs 24.1 75Emacs 24.1
76 76
77* Gave `calc-histogram' the option of using a vector to determine the bins.
78
77* Added "O" option prefix. 79* Added "O" option prefix.
78 80
79* Used "O" prefix to "d r" (`calc-radix') to turn on twos-complement mode. 81* Used "O" prefix to "d r" (`calc-radix') to turn on twos-complement mode.
diff --git a/lisp/calc/calc-vec.el b/lisp/calc/calc-vec.el
index c4de362ab36..5f426942e2f 100644
--- a/lisp/calc/calc-vec.el
+++ b/lisp/calc/calc-vec.el
@@ -451,16 +451,18 @@
451 (calc-enter-result 1 "grad" (list 'calcFunc-grade (calc-top-n 1)))))) 451 (calc-enter-result 1 "grad" (list 'calcFunc-grade (calc-top-n 1))))))
452 452
453(defun calc-histogram (n) 453(defun calc-histogram (n)
454 (interactive "NNumber of bins: ") 454 (interactive "P")
455 (unless (natnump n)
456 (setq n (math-read-expr (read-string "Centers of bins: "))))
455 (calc-slow-wrapper 457 (calc-slow-wrapper
456 (if calc-hyperbolic-flag 458 (if calc-hyperbolic-flag
457 (calc-enter-result 2 "hist" (list 'calcFunc-histogram 459 (calc-enter-result 2 "hist" (list 'calcFunc-histogram
458 (calc-top-n 2) 460 (calc-top-n 2)
459 (calc-top-n 1) 461 (calc-top-n 1)
460 (prefix-numeric-value n))) 462 n))
461 (calc-enter-result 1 "hist" (list 'calcFunc-histogram 463 (calc-enter-result 1 "hist" (list 'calcFunc-histogram
462 (calc-top-n 1) 464 (calc-top-n 1)
463 (prefix-numeric-value n)))))) 465 n)))))
464 466
465(defun calc-transpose (arg) 467(defun calc-transpose (arg)
466 (interactive "P") 468 (interactive "P")
@@ -1135,22 +1137,53 @@
1135 (if (Math-vectorp wts) 1137 (if (Math-vectorp wts)
1136 (or (= (length vec) (length wts)) 1138 (or (= (length vec) (length wts))
1137 (math-dimension-error))) 1139 (math-dimension-error)))
1138 (or (natnump n) 1140 (cond ((natnump n)
1139 (math-reject-arg n 'fixnatnump)) 1141 (let ((res (make-vector n 0))
1140 (let ((res (make-vector n 0)) 1142 (vp vec)
1141 (vp vec) 1143 (wvec (Math-vectorp wts))
1142 (wvec (Math-vectorp wts)) 1144 (wp wts)
1143 (wp wts) 1145 bin)
1144 bin) 1146 (while (setq vp (cdr vp))
1145 (while (setq vp (cdr vp)) 1147 (setq bin (car vp))
1146 (setq bin (car vp)) 1148 (or (natnump bin)
1147 (or (natnump bin) 1149 (setq bin (math-floor bin)))
1148 (setq bin (math-floor bin))) 1150 (and (natnump bin)
1149 (and (natnump bin) 1151 (< bin n)
1150 (< bin n) 1152 (aset res bin
1151 (aset res bin (math-add (aref res bin) 1153 (math-add (aref res bin)
1152 (if wvec (car (setq wp (cdr wp))) wts))))) 1154 (if wvec (car (setq wp (cdr wp))) wts)))))
1153 (cons 'vec (append res nil)))) 1155 (cons 'vec (append res nil))))
1156 ((Math-vectorp n) ;; n is a vector of midpoints
1157 (let* ((bds (math-vector-avg n))
1158 (res (make-vector (1- (length n)) 0))
1159 (vp (cdr vec))
1160 (wvec (Math-vectorp wts))
1161 (wp wts)
1162 num)
1163 (while vp
1164 (setq num (car vp))
1165 (let ((tbds (cdr bds))
1166 (i 0))
1167 (while (and tbds (Math-lessp (car tbds) num))
1168 (setq i (1+ i))
1169 (setq tbds (cdr tbds)))
1170 (aset res i
1171 (math-add (aref res i)
1172 (if wvec (car (setq wp (cdr wp))) wts))))
1173 (setq vp (cdr vp)))
1174 (cons 'vec (append res nil))))
1175 (t
1176 (math-reject-arg n "*Expecting an integer or vector"))))
1177
1178;;; Replace a vector [a b c ...] with a vector of averages
1179;;; [(a+b)/2 (b+c)/2 ...]
1180(defun math-vector-avg (vec)
1181 (let ((vp (cdr vec))
1182 (res nil))
1183 (while (and vp (cdr vp))
1184 (setq res (cons (math-div (math-add (car vp) (cadr vp)) 2) res)
1185 vp (cdr vp)))
1186 (cons 'vec (reverse res))))
1154 1187
1155 1188
1156;;; Set operations. 1189;;; Set operations.