[Maxima] only defined points plotting
Andrej Vodopivec
andrej.vodopivec at gmail.com
Fri Mar 24 12:31:12 CST 2006
------=_Part_2391_17568870.1143225072900
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
> i think i am in favor of this. it should be maintained by set_plot_option
> (i.e., not a global flag). how is this going to work, exactly?
I have attached a patch for plot.lisp which implements this. As you
can see the adaptive plotter has to be modified too (for efficiency
reasons).
Use it like
plot2d(log(sin(x)), [x,-6,6]);
plot2d(log(sin(x)), [x,-6,6], [plot_realpart, false]);
(I haven't tested it much though).
Andrej
------=_Part_2391_17568870.1143225072900
Content-Type: application/octet-stream; name=plot.lisp.patch
Content-Transfer-Encoding: 7bit
X-Attachment-Id: f_el6uk8wx
Content-Disposition: attachment; filename="plot.lisp.patch"
Index: src/plot.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/plot.lisp,v
retrieving revision 1.61
diff -u -r1.61 plot.lisp
--- src/plot.lisp 10 Feb 2006 06:49:35 -0000 1.61
+++ src/plot.lisp 24 Mar 2006 02:01:46 -0000
@@ -71,10 +71,20 @@
"set size 1.5, 1.5;set term postscript eps enhanced color solid 24")
((mlist) $logx nil)
((mlist) $logy nil)
+ ((mlist) $plot_realpart t)
))
(defvar $viewps_command "(ghostview \"~a\")")
+(defvar *plot-realpart* t)
+
+(defun maybe-realpart (x)
+ (if *plot-realpart*
+ ($realpart x)
+ (if (eq 0 ($imagpart x))
+ x
+ nil)))
+
;;(defvar $viewps_command "(gs -I. -Q ~a)")
;;(defvar $viewps_command "echo /def /show {pop} def | cat - ~a | x11ps")
@@ -153,6 +163,7 @@
($adapt_depth (check-list-items name (cddr value) 'fixnum 1))
($logx value)
($logy value)
+ ($plot_realpart value)
(t
(merror "Unknown plot option specified: ~M" name))))
(loop for v on (cdr $plot_options)
@@ -518,7 +529,7 @@
(coerce `(lambda ,(cdr args)
(declare (special ,@(cdr args)))
(let* (($ratprint nil) ($numer t)
- (result ($realpart (meval* ',(nth 2 mexpr)))))
+ (result (maybe-realpart (meval* ',(nth 2 mexpr)))))
(if ($numberp result)
($float result)
nil)))
@@ -530,7 +541,7 @@
(coerce `(lambda ,(cdr args)
(declare (special ,@(cdr args)))
(let* (($ratprint nil) ($numer t)
- (result ($realpart (meval* ',(nth 2 expr)))))
+ (result (maybe-realpart (meval* ',(nth 2 expr)))))
(if ($numberp result)
($float result)
nil)))
@@ -555,12 +566,12 @@
#-gcl
(handler-case
(catch 'errorsw
- ($float ($realpart (meval* ',expr))))
+ ($float (maybe-realpart (meval* ',expr))))
(arithmetic-error () t))
#+gcl
(handler-case
(catch 'errorsw
- ($float ($realpart (meval* ',expr))))
+ ($float (maybe-realpart (meval* ',expr))))
(cl::error () t))
))
result)))
@@ -880,6 +891,16 @@
b f-b
b1 f-b1
c f-c))
+ ;; We are not plotting the real part of the function and the
+ ;; function is undefined at all points - assume it has complex value
+ ;; on [a,b]. Maybe we should refine it a couple of times just to make sure?
+ ((and (null *plot-realpart*)
+ (null f-a) (null f-a1) (null f-b) (null f-b1) (null f-c))
+ (list a f-a
+ a1 f-a1
+ b f-b
+ b1 f-b1
+ c f-c))
(t
;; Need to refine. Split the interval in half, and try to plot each half.
(let ((left (adaptive-plot fcn a a1 b f-a f-a1 f-b (1- depth) (* 2 eps)))
@@ -1129,12 +1150,14 @@
(defun $plot2d (fun &optional range &rest options)
(let (($numer t)
($display2d nil)
+ (*plot-realpart* *plot-realpart*)
(i 0)
($plot_options $plot_options)
plot-format gnuplot-term gnuplot-out-file file plot-name)
(dolist (v options)
($set_plot_option v))
+ (setq *plot-realpart* ($get_plot_option '$plot_realpart 2))
(when (and (consp fun) (eq (cadr fun) '$parametric))
(or range (setq range (nth 4 fun)))
(setf fun `((mlist) ,fun)))
------=_Part_2391_17568870.1143225072900--
More information about the Maxima
mailing list