Same question:

kx, ky = var('kx', 'ky', domain='real')
k = vector( [kx, ky] )

d1 = vector( [0,1/sqrt(3)] )
d2 = vector( [-1/2,-1/(2*sqrt(3))] )
d3 = vector( [1/2,-1/(2*sqrt(3))] )

hk(kx,ky) = -exp(I*k.dot_product(d1)) - exp(I*k.dot_product(d2)) - 
exp(I*k.dot_product(d3))
ek(kx,ky) = sqrt((hk(kx,ky).real_part())**2 + (hk(kx,ky).imag_part())**2)
contour_plot(ek(kx,ky),(kx,-2*pi,2*pi),(ky,-2*pi,2*pi))

works

However, the "simpler"

ek(kx,ky) = abs(hk(kx,ky))
contour_plot(ek(kx,ky),(kx,-2*pi,2*pi),(ky,-2*pi,2*pi))

does not work.

A simple example would be:
    x, y = var('x', 'y', domain = 'real')
    contour_plot( abs( exp(I*x) ), (x, -pi, pi), (y, -pi, pi) )

giving the same error: "TypeError: unable to coerce to a real number"

Alberto.




Le mardi 28 janvier 2014 19:26:35 UTC+1, Albert Schueller a écrit :
>
> This morning I figured out how to plot the modulus of a complex function 
> in sage.  In my travails I wondered why the first snippet works, but the 
> second does not?  Is there any easy way to make the second snippet work?
>
> #Plot the modulus of the function, works
> var('z',domain=CC)
> var('x y', domain=RR)
> var('rp ip')
> z=x+i*y
> rp = (2+z.conjugate()+z^3).real()
> ip = (2+z.conjugate()+z^3).imag()
> m(x,y) = sqrt(rp^2+ip^2)
> plot3d(m(x,y).simplify(),(x,-1.5,1.5),(y,-1.5,1.5))
>
>
>
>
> My question is, why doesn't this work?
>
> #Plot the modulus of the function, fails
> var('z',domain=CC)
> var('x y', domain=RR)
> z=x+i*y
> m(x,y) = abs(2+z.conjugate()+z^3)
> plot3d(m(x,y),(x,-1.5,1.5),(y,-1.5,1.5))
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to