diff options
| author | Jay Belanger | 2010-05-15 23:43:09 -0500 |
|---|---|---|
| committer | Jay Belanger | 2010-05-15 23:43:09 -0500 |
| commit | 597517ef8dc589e3b920a0f5bcdf55f9f6cde644 (patch) | |
| tree | 58bec545b37f91bef730a8e5f21130a5d74c64c1 | |
| parent | eba62f7a5950e77d207ea233a10597f2c9639b0b (diff) | |
| download | emacs-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'.
| -rw-r--r-- | doc/misc/ChangeLog | 7 | ||||
| -rw-r--r-- | doc/misc/calc.texi | 14 | ||||
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/calc/README | 2 | ||||
| -rw-r--r-- | lisp/calc/calc-vec.el | 71 |
5 files changed, 78 insertions, 20 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index c6d3c1be498..4c857c45a32 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -1,6 +1,11 @@ | |||
| 1 | 2010-05-16 Jay Belanger <jay.p.belanger@gmail.com> | ||
| 2 | |||
| 3 | * calc.texi (Manipulating Vectors): Mention that vectors can | ||
| 4 | be used to determine bins for `calc-histogram'. | ||
| 5 | |||
| 1 | 2010-05-13 Jay Belanger <jay.p.belanger@gmail.com> | 6 | 2010-05-13 Jay Belanger <jay.p.belanger@gmail.com> |
| 2 | 7 | ||
| 3 | * calc.texi: Remove "\turnoffactive" commands througout. | 8 | * calc.texi: Remove "\turnoffactive" commands throughout. |
| 4 | 9 | ||
| 5 | 2010-05-08 Štěpán Němec <stepnem@gmail.com> (tiny change) | 10 | 2010-05-08 Štěpán Němec <stepnem@gmail.com> (tiny change) |
| 6 | 11 | ||
diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi index c578e919612..12b8d8e162d 100644 --- a/doc/misc/calc.texi +++ b/doc/misc/calc.texi | |||
| @@ -20030,6 +20030,20 @@ range are ignored. (You can tell if elements have been ignored by noting | |||
| 20030 | that the counts in the result vector don't add up to the length of the | 20030 | that the counts in the result vector don't add up to the length of the |
| 20031 | input vector.) | 20031 | input vector.) |
| 20032 | 20032 | ||
| 20033 | If no prefix is given, then you will be prompted for a vector which | ||
| 20034 | will be used to determine the bins. (If a positive integer is given at | ||
| 20035 | this prompt, it will be still treated as if it were given as a | ||
| 20036 | prefix.) Each bin will consist of the interval of numbers closest to | ||
| 20037 | the corresponding number of this new vector; if the vector | ||
| 20038 | @expr{[a, b, c, ...]} is entered at the prompt, the bins will be | ||
| 20039 | @expr{(-inf, (a+b)/2]}, @expr{((a+b)/2, (b+c)/2]}, etc. The result of | ||
| 20040 | this command will be a vector counting how many elements of the | ||
| 20041 | original vector are in each bin. | ||
| 20042 | |||
| 20043 | The result will then be a vector with the same length as this new vector; | ||
| 20044 | each element of the new vector will be replaced by the number of | ||
| 20045 | elements of the original vector which are closest to it. | ||
| 20046 | |||
| 20033 | @kindex H v H | 20047 | @kindex H v H |
| 20034 | @kindex H V H | 20048 | @kindex H V H |
| 20035 | With the Hyperbolic flag, @kbd{H V H} pulls two vectors from the stack. | 20049 | With the Hyperbolic flag, @kbd{H V H} pulls two vectors from the stack. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 27574c31d55..23338834d63 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2010-05-16 Jay Belanger <jay.p.belanger@gmail.com> | 1 | 2010-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 | ||
| 75 | Emacs 24.1 | 75 | Emacs 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. |