Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 2011-10-09 12:44:12 -0600

DSM gravatar image

I can't reproduce the error (4.7.1), but I can see at least one problem.

The way the scoping works, f(g1, g2) is evaluated before the plot is made, so your plot will be zero everywhere. Stick a "print g1,g2" inside the function to convince yourself this is true. You probably want "f" instead of "f(g1,g2)".

The following seems to work for me. Note that I've also changed it so that it returns 0 instead of None sometimes like your original code did-- if that's what you want, switch back.

var("g1 g2")
def f(g1, g2):
    if g1*g2 > 0.0:
        if abs(g2) < 1/abs(g1):
            return sqrt(0.5*((1+g1*g2)*abs(g1+g2))/(sqrt((1.0-g1*g2)^3)*g1*g2))
    return 0

z=contour_plot(f, (g1,-4,4), (g2,-4,4),plot_points=500, cmap='afmhot_r', colorbar=True, contours=srange(1,6,0.5))
show(z)

image description

I can't reproduce the error (4.7.1), but I can see at least one problem.

The way the scoping works, f(g1, g2) is evaluated before the plot is made, so your plot will be zero (or maybe None) everywhere. Stick a "print g1,g2" inside the function to convince yourself this is true. You probably want "f" instead of "f(g1,g2)".

The following seems to work for me. Note that I've also changed it so that it returns 0 instead of None sometimes like your original code did-- if that's what you want, switch back.

var("g1 g2")
def f(g1, g2):
    if g1*g2 > 0.0:
        if abs(g2) < 1/abs(g1):
            return sqrt(0.5*((1+g1*g2)*abs(g1+g2))/(sqrt((1.0-g1*g2)^3)*g1*g2))
    return 0

z=contour_plot(f, (g1,-4,4), (g2,-4,4),plot_points=500, cmap='afmhot_r', colorbar=True, contours=srange(1,6,0.5))
show(z)

image description