Sterling wrote:
> I'm trying to duplicate what this Mathematica code does in SAGE:
> 
> F[z_]=4*Log[z^3]-2*Log[z^3-8]
> a=ContourPlot[If[y<Sqrt[3]*x, Im[F[x+I*y]]], {x, 0, 4}, {y, 0, 4},
> ContourShading->False, Contours->30]
> b=Plot[Sqrt[3]*x, {x, 0, 4}]
> Show[a, b]
> 
> I originally used this (this doesn't include the sqrt(3)*x line in the
> code above):
> 
> z = var('z')
> f(z) = 4*log(z^3)-2*log(z^3-8)
> g = lambda x,y: imag(f(x+y*I))
> a = contour_plot(g,(x,0,4),(y,0,4),fill=False,contours=30)
> 
> Robert Bradshaw suggested I use:
> 
> g = lambda x,y: imag(f(x+y*I)) if y < sqrt(3)*x else float('nan')
> 
> It works, but as Robert said, it isn't really pretty. Any suggestions?


You could write it out:

def g(x,y):
     if y < sqrt(3)*x:
         return imag(f(x+y*I))
     else:
         return float('nan')

Is that prettier?

Note that if you give a pure python function like this, it doesn't make 
sense to specify the variable names in the contour_plot statement, as 
the arguments are just stuffed into the functions in the order.

Hmm...should we analyze the function's argument names so that

def f(x,y):
    return x*sin(y)
plot3d(f, (x,0,3),(y,-6,6))

and

plot3d(f, (y,0,3),(x,-6,6))

give the same plots?


In fact, suprisingly, if f is defined as

f(x,y)=x*sin(y)

then the above do *not* return the same plots.  That seems like a bug.

See http://sagenb.org/home/pub/1107/ (I think each of those plots should 
be exactly the same).

and http://trac.sagemath.org/sage_trac/ticket/7512

Jason


-- 
Jason Grout

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to