[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re:
- To: info-mcl@cambridge.apple.com
- Subject: Re:
- From: Robert Bruce Findler <robby+@CMU.EDU>
- Date: Wed, 20 Oct 1993 15:33:34 -0400 (EDT)
- Cc:
- In-reply-to: <9310192316.AA10137@rufus.ucsc.edu>
Excerpts from internet.listserv.info-mcl: 19-Oct-93 by David Evan
Jones@cats.uc
> BUT, how about simple plotting of functions on a matrix?
> (Plotting the likes of f(x) = sin (x).) Any code out
> there?
>
As far as printing out curves, I wrote some stuff to do that for testing
the spline code out in Numerical Recipies. Here it is:
(require 'quickdraw)
(defclass graph-window (window)
((x :accessor x :initform nil :initarg :x)
(y :accessor y :initform nil :initarg :y)))
(defmethod view-draw-contents ((w graph-window))
(flet ((scaler (xi max-xi min-xi win-max)
(floor (pin-between (* (/ (- xi min-xi) (- max-xi min-xi))
win-max) -32768 32767))))
(let* ((min-x (apply #'min (x w)))
(max-x (apply #'max (x w)))
(min-y (apply #'min (y w)))
(max-y (apply #'max (y w)))
(scaled-x (mapcar #'(lambda (x) (scaler x max-x min-x
(point-h (view-size w))))
(x w)))
(scaled-y (mapcar #'(lambda (y) (scaler y max-y min-y
(point-v (view-size w))))
(y w))))
(with-fore-color *light-blue-color*
(move-to w 0 (scaler 0 max-y min-y (point-v (view-size w))))
(line w (point-h (view-size w)) 0)
(move-to w (scaler 1 max-x min-x (point-h (view-size w)))
(scaler 1 max-y min-y (point-v (view-size w))))
(line-to w (scaler 1 max-x min-x (point-h (view-size w)))
(scaler -1 max-y min-y (point-v (view-size w))))
(line-to w (scaler -1 max-x min-x (point-h (view-size w)))
(scaler -1 max-y min-y (point-v (view-size w))))
(line-to w (scaler -1 max-x min-x (point-h (view-size w)))
(scaler 1 max-y min-y (point-v (view-size w))))
(line-to w (scaler 1 max-x min-x (point-h (view-size w)))
(scaler 1 max-y min-y (point-v (view-size w))))
(move-to w (scaler 0 max-x min-x (point-h (view-size w))) 0)
(line w 0 (point-v (view-size w))))
(move-to w 0 0)
(mapcar #'(lambda (x y) (pen-normal w)
(line-to w x y)
(move-to w x y)
; (set-pen-size w 2 2)
(line w 0 0))
scaled-x scaled-y))))
(defun graph (x y)
(make-instance 'graph-window :x x :y y))
(defun first-somethings (succ inital)
#'(lambda (top)
(labels ((f (x n) (if (equalp x n) (list n) (cons x (f (funcall
succ x) n)))))
(f inital top))))
(setf (symbol-function 'nats-up-to) (first-somethings #'1+ 0))
; "pins" x between l and r
;input: numbers
;output: x if x is between l and r, and the closer one if it isn't.
(defun pin-between (x l r)
(min r (max l x)))
(defun graph-function (x-min x-max f &optional (print-stuff? nil)
(resolution 100))
(let* ((res (1- resolution))
(x-vals (mapcar #'(lambda (x) (+ x-min (* (/ x res) (- x-max x-min))))
(nats-up-to res)))
(y-vals (mapcar #'(lambda (x) (- (funcall f x))) x-vals)))
(graph x-vals y-vals)
(when print-stuff?
(format t "last: ~a~%" (last y-vals)))))
It's a bit of a hodge podge, since I use a few functions from my utils
library, but I hope it's useful.
__________________________________________________________________________
Robby Findler robby+@cmu.edu
Carnegie Mellon University Pittsburgh, PA (412) 681-4552