On 3/23/06, Andrej Vodopivec <andrej.vodopivec at gmail.com> wrote:
> Since there is no way to force plot2d to plot the way you want maybe
> you can change the function to return values only when they are real:
>
> (%i1) my_sqrt(x) := if x>=0 then sqrt(x);
> (%o1) my_sqrt(x):=if x>=0 then sqrt(x)
> (%i2) plot2d(['(my_sqrt(x^2-3))], [x,-5,5], [y,-4,4], [gnuplot_preamble, "set
> xrange [-5:5]; set yrange [-4:4];"])$
how about plot2d ('(sqrt (x), if imagpart (%%) = 0 then %%), [x, -5, 5]); ?
then the user doesn't need to know where sqrt (or whatever) is complex.
the disadvantage of this approach is that sometimes small
imaginary values (e.g. 1e-15 * %i) can creep in; the hack shown
above will throw out the real part too. ideally the imagpart = 0
business would be handled by simplification (i.e., applying
properties and identities).
> Adding another option variable which would make plot2d to plot a
> function only where the value is real would be trivial. Maybe we
> should consider it?
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?
best,
robert