Re: [sage-newbie] Re: Implicit Plotting?

210 views
Skip to first unread message

William Stein

unread,
Jan 19, 2008, 9:07:51 AM1/19/08
to sage-...@googlegroups.com, sage-...@googlegroups.com
On Jan 19, 2008 5:40 AM, David Joyner <wdjo...@gmail.com> wrote:
>
> implicit plot doesn't yet exist in SAGE.

This is kind of getting old. How do programs implement implicit
plotting, say of F(x,y) = 0? Is it something we could just
implement in two hours?

Do they;
(1) For symbolic expressions try to solve for one variables (say y)
using a symbolic solver, and if so plot the union of all solutions y =
.... that are real?
E.g., to plot y^2 - x^3 - x implicitly, one could do:

sage: var('x,y')
(x, y)
sage: solve(y^2 - x^3 - x == 0, [y])
[y == -sqrt(x)*sqrt(x^2 + 1), y == sqrt(x)*sqrt(x^2 + 1)]

then just plot each of those two above and combine them.

(2) If solving symbolically fails, or is impossible, e.g., if the
input is a Python function
with no symbolic meaning, fall back to some uniform sampling of the rectangular
region where we are plotting the function. In this case, we are really
iteratively finding
solutions to an equations F(x,y) = 0, and plotting a dot or something
at every point
we find, and possibly connecting the dots. How does one do that.


I think (1) above would already be pretty useful and easy to implement.
I bet Josh Kantor or Carl Witty will have something to say about (2).

And if I'm just completely wrong about what to do, then that's good too because
it's about time to discuss this.


> In the case of the circle, you can parameterize it and use parametric_plot,
> http://www.sagemath.org/doc/html/ref/module-sage.plot.plot.html#l2h-564
> In the case of a curve F(x,y)=c, you can use contour plot
> http://www.sagemath.org/doc/html/ref/module-sage.plot.plot.html#l2h-575
> If you install the gnuplot package then you can use the maxima
> interface to gnuplot (maxima has implicit plot
> http://maxima.sourceforge.net/docs/manual/en/maxima_55.html#IDX2072)
> I think if you install the fricas4sage page then you can use that package for
> implicit plot, though I haven't tried that.
>
>
> On Jan 19, 2008 3:44 AM, Dagda <phyzik...@gmail.com> wrote:
> >
> > Hi,
> > I was wondering if there was a way to plot relations implicitly, in 2D
> > and/or 3D. A simple example would be to plot a circle with something
> > like the following:
> >
> > plot_implicit(x^2+y^2=1)
> >
> > Thanks!
> > -Pavan
> > >
> >
>
> >
>

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Harald Schilly

unread,
Jan 19, 2008, 10:04:17 AM1/19/08
to sage-devel
On Jan 19, 3:07 pm, "William Stein" <wst...@gmail.com> wrote:
> How do programs implement implicit
> plotting, say of F(x,y) = 0?

First, this is just a special case of contour plots. There you seek
for an area where F is inside an interval, e.g. 0 to 1 or 50 to 150 -
and colorcode them. Here you just have two intervals, (-oo,0) and
(0,oo)

To solve this, in my opinion the straight forward idea is to
iteratively refine a fixed grid of points at those subrectangles where
the edges are not all below or above 0. Then you get more samples to
track down the path of the curve. Next, after the one or two
iterations, interpolate the intersection points on the lines of the
grid (e.g. between -0.02 and 0.1 it's nearer to the first one). Then
draw the curve along those points.
I think, there are already methods for doing this in a nice way
because level-set theory uses these ideas to calculate their models.

Solving and combining is bad, because, how do you combine?

H

Joshua Kantor

unread,
Jan 19, 2008, 7:05:41 PM1/19/08
to sage-devel
I don't know for sure how other systems actually implement implicit
plotting.

I would think you might try to use that the gradient of F
is orthogonal to the level set curves. In particular
if (x_0,y_0) is a solution to F(x,y)=0, you know that to follow
the level set curve you should move in a direction orthogonal to the
gradient.

One could try an algorithm where you find a point on the level set,
then follow the curve by

1. Taking a step in the direction orthogonal to the gradient,
which will go in the right direction but might take you off the level
set,

2 . Numerically minimize |F(x,y)| to get back on the level set.

rinse and repeat

Actually searching I found the following

http://www.tangentspace.net/cz/archives/2007/08/implicit-plotting-code-for-mathematica/

cute explanation of basically the algorithm I described above, with a
reference for how to do
the analagous thing to triangulate an implicilty defined surface in
3d, so I'm pretty sure
something like what I describe would work.
Reply all
Reply to author
Forward
0 new messages