Utilisation de cl-plplot avec sbcl.

Documentation

Fonction affine définie  sur l'inervalle [-4  4]

Avec do
Avec la boucle dotimes

(use-package :cl-plplot-system)
(defparameter flin #'(lambda (x) (+ (/ x 2) 2)))
(defparameter gdev "png")
;; (defparameter gdev "xfig")
;; (defparameter gdev "xwin")

(defun my-make-array (dims)
(make-array dims :initial-element 0.0 :element-type 'float))

(defun display-curve (n func)
(let ((x (my-make-array n))
(y (my-make-array n)))
(dotimes (i n)
(let ((tmp (* 0.1 (- i (round (/ n 2))))))
(setf (aref x i) tmp)
(setf (aref y i) (funcall func tmp))))
(plcol0 3) ;; color de la courbe
(plline x y)))

(defun affine-fn ()
(plsdev gdev)
(plsfnam "lin2.png")
(plinit)
(plcol0 1)
(plwid 1.3)
(plenv -4 4 0 5 0 2)
(plbox "g" 1 0 "g" 1 0)
(plcol0 2)
(pllab "x" "y" "linear function")
(display-curve 81 flin)
(plend))

(affine-fn)
;; (run-program "/usr/bin/xfig" '("-nosp" "lin2.fig"))
(run-program "/usr/bin/display" '("lin2.png"))

Avec dotimes

Avec la boucle do

(use-package :cl-plplot-system)
(defparameter flin #'(lambda (x) (+ (/ x 2) 2)))
(defparameter gdev "png")
;; (defparameter gdev "xfig")
;; (defparameter gdev "xwin")

(defun my-make-array (dims)
(make-array dims :initial-element 0.0 :element-type 'float))

(defun display-curve (a1 a2 func)   ;; la courbe est définie sur l'intervalle [a1 a2]
(let* ((nab (round (* 10 (abs (- a2 a1)))))
(x (my-make-array nab))
(y (my-make-array nab)))
(do ((i 0 (1+ i)) (xax a1 (+ 0.1 xax)))((> i (1- nab)))
(setf (aref x i) xax)
(setf (aref y i) (funcall func xax)))
(plcol0 3) ;; color de la courbe
(plline x y)))

(defun affine-fn ()
(plsdev gdev)
(plsfnam "lin2.png")
(plinit)
(plcol0 1)
(plwid 1.3)
(plenv -4 4 0 5 0 2)
(plbox "g" 1 0 "g" 1 0)
(plcol0 2)
(pllab "x" "y" "linear function")
(display-curve -4 4.1 flin)
(plend))

(affine-fn)
;; (run-program "/usr/bin/xfig" '("-nosp" "lin2.fig"))
(run-program "/usr/bin/display" '("lin2.png"))

Haut de page