Replace uses of the deprecated function GENTEMP in share
[maxima.git] / archive / src / nutplot.lisp
blobd1dfdbe3c3e8a4514fe9114dceb1f1eeedd2e68a
1 (in-package "MAXIMA")
2 #|
3 Sample usage:
4 (C24) f(x):=2^x+3;
6 (D24) F(X) := 2 + 3
7 (C25) nutmeg_plot_fun(f,-2,2);
8 Loading raw file 'max.raw' ... done.
10 Title: Maxima plot
11 Name: ourplot
12 Date: Sun Oct 29 17:51:15 1989
15 This is a sample news file, and will be printed
16 whenever spice or nutmeg is started.
18 nutmeg 1 -> plot y
19 nutmeg 2 -> \x04
20 quit
21 So long.
22 (D25) #/rascal/public/tmp/spice3c1/max.raw
25 ;; The left button if held down while moving between two points,
26 ;; will print the difference.
27 ;;
29 (defun print-date (&optional(stream *standard-output*)
30 (time (get-universal-time)))
31 (multiple-value-bind (sec min hr day mon yr wkday)
32 (decode-universal-time time)
33 (format stream "~a ~a ~a ~d:~2,'0d:~2,'0d ~a"
34 (nth wkday '( "Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"))
35 (nth (1- mon) '("Jan" "Feb" "Mar" "Apr" "May" "Jun"
36 "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
37 day
38 hr min sec yr)))
40 (defun plot-points (variables pts &optional (st *standard-output* )
41 &uax (npoints (length (elt pts 0))))
42 (format st "~%Title: Maxima plot")
43 (format st "~%Date: ~a" (print-date nil))
44 (format st "~%Plotname: ourplot")
45 (format st "~%Flags: real")
46 (format st "~%No. Variables: ~a ~%No. Points: ~a" (length variables) npoints)
47 (format st "~%Variables:")
48 (sloop for i from 0 for v in variables
49 do (format st "~%~a ~a ~a" i v v))
50 (format st "~%Values:")
51 (sloop for j below npoints
52 do (format st "~%~d " j)
53 (cond ((arrayp (car pts))
54 (sloop for v in pts
55 do (princ (float (aref v j)) st)
56 (princ " " st)
57 )))))
59 (defun $nutmeg_plot_fun (f min max &aux file )
60 (let ((x (make-array $plotnum))
61 (y (make-array $plotnum)))
62 (translate-function f)
63 (sloop for i below $plotnum
64 with del = (/ (- max min) (float $plotnum))
66 (setf (aref x i) (+ min (* i del)))
67 (setf (aref y i) (funcall f (aref x i))))
68 (with-open-file(st "max.raw" :direction :output)
69 (plot-points '(x y) (list x y) st)
70 (setq file (truename st)))
71 (system "nutmeg max.raw")
72 file))
75 (defun $nutmeg_plot(vars vals)
76 (setq vals
77 (sloop for v in (cdr vals)
78 collect (cond ((listp v) (coerce v 'vector))
79 (t v))))
80 (plot-points (cdr variables) (cdr pts)))