Ali Onur Cinar
Articles

STATISTICAL FUNCTIONS

Some statistical functions. It's not complete yet...


;
; Copyright (c) 2003
;      Ali Onur Cinar &060;cinar&064;zdo.com&062;
;
; License:
;
;   Permission  to  use,  copy, modify, and  distribute  this software and its
;   documentation   for  educational   purposes  and  without  fee  is  hereby
;   granted,  provided  that the  above  copyright notice appear in all copies
;   and  that both  the  copyright  notice  and  this  permission  notice  and
;   warranty  disclaimer appear in supporting documentation, and that the name
;   of Ali Onur Cinar not be  used  in  advertising or publicity pertaining to
;   distribution of the software without specific, written prior permission.
;

(defun odd (x)
 (cond ((= (mod x 2) 0) nil)
       ('t 't)))

(defun sum (lst)
 (apply '+ lst))

(defun median (lst)
 (cond ((odd (length lst)) (nth (- (/ (+ (length lst) 1) 2) 1) lst))
       ('t (let ((x (nth (/ (length lst) 2) lst))
                 (y (nth (- (/ (length lst) 2) 1) lst)))
                (/ (+ x y) 2)))))

(defun mean (lst)
 (/ (sum lst) (length lst)))

;
; Testing
;

(format t "~s~%" (median '(1 2 3 4 5 6)))
(format t "~s~%" (median '(1 2 3)))
(format t "~s~%" (median '(3)))

(format t "~s~%" (sum '(1 2 3 4 5 6)))
(format t "~s~%" (mean '(1 2 3 4 5 6)))


Your Comments


12/31/69 17:00

Name:
Comment:

Valid XHTML 1.0! Valid CSS! FuseBox Inside This is my Google PageRank. - SmE Rank free service Powered by Scriptme

This page was last updated on Sun January 21 2007 06:55:17 PM