Ask Your Question
1

3d plot with restricted range

asked 2013-09-29 06:08:06 +0200

Peter Luschny gravatar image

updated 2013-09-30 04:17:34 +0200

Can someone please give me a helping hand with plot3d?

I want to plot the GammaCondor-function:

def condor(x, y):
    e = gamma(y+1)
    a = gamma(1/2*y-1/2*x+1/2)
    b = gamma(-1/2*x+1/2*y+1)
    c = gamma(1/2*x+1/2*y+1/2)
    d = gamma(1/2*x+1/2*y+1)

    alpha = cos(pi*(y-x))
    beta  = cos(pi*(y+x))

    return log(e)+log(a)*((alpha-1)/2)+log(b)*((-alpha-1)/2) \
    +log(c)*((beta-1)/2)+log(d)*((-beta-1)/2)

With Maple this is easy (note the restriction for x):

plot3d(condor(x, y), x = -y..y, y = 0..8, 
       orientation = [-145, -105], axes = BOXED, grid = [64,64]);

What this looks like can be seen here: http://luschny.de/math/asy/ElCondorYE...
Or as a dynamic pdf with an Adobe Reader (v10 or later): http://luschny.de/math/asy/Condor.pdf

var('x, y')
g = plot3d(condor(x, y), (x, -y, y), (y, 0, 8))
show(g)

gives a TypeError.

var('x, y')
g = plot3d(condor(x, y), (x, -8, 8), (y, 0, 8))
show(g)

shows an empty frame. Plotting was tried on cloud.sagemath.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-09-29 10:01:34 +0200

tmonteil gravatar image

updated 2013-09-29 11:42:19 +0200

First, i can not reproduce your last problem about the empty frame from the Sage command line. By default, plot3d() uses jmol, which is a java applet launched from your web browser. So your web browser should be able to run java. If you use firefox/iceweasel under ubuntu/debian, just install the default-jre and icedtea6-plugin packages.

Another possibility is to use another 3D viewer, like tachyon:

sage: g = plot3d(condor(x, y), (x, -8, 8), (y, 0, 8), viewer='tachyon')
sage: show(g)

Concerning your question about plotting a non-rectangular range, plot3d() lacks a region parameter (which implicit_plot3d() has). So you have to do it yourself. Here is a possibility: define a function that returns condor(x,y) inside your region and returns NaN (not a number) outside the region, as follows:

sage: f = lambda x, y: condor(x,y) if abs(x) <= y else NaN
sage: plot3d(f, (-8, 8), (0, 8))
sage: plot3d(f, (-8, 8), (0, 8), viewer='tachyon')
edit flag offensive delete link more

Comments

As I said my computing environment is cloud.sagemath. No Java, no JMOL there, instead three.js and webgl. Unfortunately your recipe does not work (empty frame), with or without 'tachyon'. See https://plus.google.com/115360165819500279592/posts/bZrKuNxfne5

Peter Luschny gravatar imagePeter Luschny ( 2013-09-30 04:14:12 +0200 )edit

In the Javascript debugger in cloud.sagemath it says "Uncaught SyntaxError: Unexpected token I", which means there is a bug -- something is wrong with how the scene is getting translated from Python to a JSON representation. Thanks for the bug report. This is now https://github.com/sagemath/cloud/issues/28

William Stein gravatar imageWilliam Stein ( 2013-09-30 10:54:17 +0200 )edit

This bug is now also a bug in the sage cell server: http://sagecell.sagemath.org/?q=acedhv So, I'm encouraging them to fix it there.

William Stein gravatar imageWilliam Stein ( 2013-10-18 16:59:32 +0200 )edit
1

answered 2013-12-13 07:58:00 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Jason Grout gave two solutions:

def condor(x, y):
    if -y<=x<=y:
        e = gamma(y+1)
        a = gamma(1/2*y-1/2*x+1/2)
        b = gamma(-1/2*x+1/2*y+1)
        c = gamma(1/2*x+1/2*y+1/2)
        d = gamma(1/2*x+1/2*y+1)

        alpha = cos(pi*(y-x))
        beta  = cos(pi*(y+x))

        return log(e) + log(a)*((alpha-1)/2) + log(b)*((-alpha-1)/2) \
               + log(c)*((beta-1)/2) + log(d)*((-beta-1)/2)
    else:
        return 0

g = plot3d(condor, (-8,8), (0,8))
t = threejs(g)
t.lights([sage.plot.plot3d.light.AmbientLight((0.6,0.6,0.6))])

http://sagecell.sagemath.org:8880/?q=...

Two things:

  1. right now, you have to implement the region restriction in the function itself.

  2. since we are now invoking python logic in the function, when calling plot3d, we should just specify the function without parameters.

That function will be called with the appropriate numbers when being plotted.

Here's another try, using the implicit_plot3d's region parameter:

def condor(x, y):
    e = gamma(y+1)
    a = gamma(1/2*y-1/2*x+1/2)
    b = gamma(-1/2*x+1/2*y+1)
    c = gamma(1/2*x+1/2*y+1/2)
    d = gamma(1/2*x+1/2*y+1)

    alpha = cos(pi*(y-x))
    beta  = cos(pi*(y+x))

    return log(e) + log(a)*((alpha-1)/2) + log(b)*((-alpha-1)/2) \
           + log(c)*((beta-1)/2) + log(d)*((-beta-1)/2)

var('x,y,z')
g = implicit_plot3d(z-condor(x,y), (x,-8,8), (y,0,8), (z,0,5), \
region=lambda x,y,z: -  y<=x<=y)
show(g)
t=threejs(g)
t.lights([sage.plot.plot3d.light.AmbientLight((0.6,0.6,0.6))])

http://sagecell.sagemath.org/?q=qelyzi

It looks like that initial show() is needed in the cell server; I'm not sure if it will be needed in cloud.

=== My comment:

The first solution has the drawback that it generates an artifact, a plane at the floor of the plot.

The second solution does not show this artifact but I get the message: "You do not have Java applets enabled in your web browser, or your browser is blocking this applet."

Indeed I would like a solution like the first one which does not use Java (which I consider unsafe).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-09-29 06:08:06 +0200

Seen: 59,193 times

Last updated: Dec 13 '13