Warning: Remote host denied X11 forwarding, perhaps xauth program could not be run on the server side. Index: src/plot.lisp =================================================================== RCS file: /cvsroot/maxima/maxima/src/plot.lisp,v retrieving revision 1.24 diff -u -r1.24 plot.lisp --- src/plot.lisp 13 May 2003 03:46:04 -0000 1.24 +++ src/plot.lisp 15 May 2003 03:30:31 -0000 @@ -449,9 +449,21 @@ ;(na (gensym "TMPF")) ) (coerce `(lambda ,(cdr vars) - (declare (special ,@(cdr vars))) - (let (($ratprint nil)) - ($float ($realpart (meval* ',expr))))) + (declare (special ,@(cdr vars) errorsw)) + (let (($ratprint nil) + (errorsw t)) + ;; Catch any errors from evaluating the + ;; function. We're assuming that if an error + ;; is caught, the result is not a number. We + ;; also assume that for such errors, it's + ;; because the function is not defined there, + ;; not because of some other maxima error. + (let ((result + (catch 'errorsw + ($float ($realpart (meval* ',expr)))))) + (unless (numberp result) + (format t "fun returned ~A~%" result)) + result))) 'function))))) (defmacro zval (points verts i) `(aref ,points (f+ 2 (f* 3 (aref ,verts ,i))))) @@ -687,10 +699,15 @@ ;; are not monotonic. (defun slow-oscillation-p (f0 f1 f2 f3 f4) (flet ((sign-change (x y z) - (if (or (and (> y x) (> y z)) - (and (< y x) (< y z))) - 1 - 0))) + (cond ((not (and (numberp x) (numberp y) (numberp z))) + ;; Something is not a number. Assume the + ;; oscillation is not slow. + 2) + ((or (and (> y x) (> y z)) + (and (< y x) (< y z))) + 1) + (t + 0)))) (<= (+ (sign-change f0 f1 f2) (sign-change f1 f2 f3) (sign-change f2 f3 f4)) @@ -702,24 +719,28 @@ ;; ;; (defun smooth-enough-p (f-a f-a1 f-b f-b1 f-c eps) - (let ((quad (/ (+ f-a - (* -5 f-a1) - (* 9 f-b) - (* -7 f-b1) - (* 2 f-c)) - 24)) - (quad-b (/ (+ (* 5 f-b) - (* 8 f-b1) - (- f-c)) - 12))) - ;; According to the Yacas source code, quad is the Simpson - ;; quadrature for the (fb,fb1) subinterval (using points b,b1,c), - ;; subtracted from the 4-point Newton-Cotes quadrature for the - ;; (fb,fb1) subinterval (using points a, a1, b, b1. - ;; - ;; quad-b is the Simpson quadrature for the (fb,f1) subinterval. - (<= (abs quad) - (* eps (- quad-b (min f-a f-a1 f-b f-b1 f-c)))))) + (cond ((every #'numberp (list f-a f-a1 f-b f-b1 f-c)) + (let ((quad (/ (+ f-a + (* -5 f-a1) + (* 9 f-b) + (* -7 f-b1) + (* 2 f-c)) + 24)) + (quad-b (/ (+ (* 5 f-b) + (* 8 f-b1) + (- f-c)) + 12))) + ;; According to the Yacas source code, quad is the Simpson + ;; quadrature for the (fb,fb1) subinterval (using points b,b1,c), + ;; subtracted from the 4-point Newton-Cotes quadrature for the + ;; (fb,fb1) subinterval (using points a, a1, b, b1. + ;; + ;; quad-b is the Simpson quadrature for the (fb,f1) subinterval. + (<= (abs quad) + (* eps (- quad-b (min f-a f-a1 f-b f-b1 f-c)))))) + (t + ;; Something is not a number, so assume it's not smooth enough. + nil))) (defun adaptive-plot (f a b c f-a f-b f-c depth eps) @@ -774,7 +795,8 @@ (do ((x result (cddr x)) (y (cdr result) (cddr y))) ((null y)) - (unless (<= ymin (car y) ymax) + (unless (and (numberp (car y)) + (<= ymin (car y) ymax)) (setf (car x) 'moveto) (setf (car y) 'moveto))) (cons '(mlist) result))))) @@ -837,9 +859,9 @@ (defvar $openmath_plot_command "omplotdata") -(defun $plot2d(fun &optional range &rest options &aux ($numer t) $display2d - (i 0) plot-format file plot-name - ($plot_options $plot_options)) +(defun $plot2d (fun &optional range &rest options &aux ($numer t) $display2d + (i 0) plot-format file plot-name + ($plot_options $plot_options)) (dolist (v options) ($set_plot_option v)) (or ($listp fun ) (setf fun `((mlist) ,fun))) (cond ((eq (cadr fun) '$parametric) @@ -854,9 +876,10 @@ (with-open-file (st file :direction :output) (dolist (v (cdr fun)) (incf i) - (setq plot-name (let ((string (coerce (mstring v) 'string))) - (cond ((< (length string) 9) string) - (t (format nil "Fun~a" i))))) + (setq plot-name + (let ((string (coerce (mstring v) 'string))) + (cond ((< (length string) 9) string) + (t (format nil "Fun~a" i))))) (case plot-format ($xgraph (format st "~%~% \"~a\"~%" plot-name)) @@ -866,9 +889,12 @@ (sloop for (v w) on (cdr (draw2d v range )) by 'cddr do (cond ((eq v 'moveto) - (unless (equal plot-format '$gnuplot) - (format st "move "))) - (t (format st "~,3f ~,3f ~%" v w)))))) + (cond ((equal plot-format '$gnuplot) + ;; A blank line means a discontinuity + (format st "~%")) + (t + (format st "move ")))) + (t (format st "~g ~g ~%" v w)))))) (case plot-format ($gnuplot ($system (concatenate 'string *maxima-plotdir* "/" $gnuplot_command) " -plot2d maxout.gnuplot -title '" plot-name "'"))