Hi @ppurka - thank you very much as I would never have thought of that! -
that certainly fixes the crashing problem - but I now have an even more
bizarre problem, which is that plot3d does literally nothing! I have
re-booted everything but it makes no difference. Here is my code:
s = 4
a=1/s
b=1/s
c=1/s
d=i/s
theta, phi = var('theta,phi')
def f(theta,phi): return ( (a*exp(i*theta)-1)*d*exp(i*phi) -
(b*exp(i*phi)-1)*c*exp(i*theta) ) . abs()
plot3d(f,(theta,0,pi),(phi,0,pi))
I know that plot3d works in the same notebook() session say on examples
from the SAGE Reference manual, and the function f as you defined it also
works fine on individual (pairs of) angles ... does this code work on your
computer?
Thanks again
On Wednesday, April 17, 2013 2:54:35 AM UTC+2, P Purkayastha wrote:
>
> On 04/16/2013 09:57 PM, GaryMak wrote:
> > Hi
> >
> > I am trying to use plot functions for the first time in sage - apologies
> > if this is a dumb question for a change.
> >
> > I have a square matrix M of fixed complex numbers which are then all
> > multiplied by a different phase depending on which column they are in.
> > (In the 2x2 example below M=[a,b;c,d] and column 1 is multiplied by
> > exp(i*theta) and column 2 is multiplied by exp(i*phi) ). I then take
> > another fixed matrix A away from M and take f=det(M-A).abs() as my
> > output. I have explicitly written this formula for A = [1,1;0,0] below.
> > So the function I would like to plot is f as a function of theta and phi
> > (in this case).
> >
> > a = 1/2
> > b = - i/3
> > c = 1/4
> > d = i/5
> > theta, phi = var('theta,phi')
> > f(theta,phi) = ( (a*exp(i*theta)-1)*d*exp(i*phi) -
> > (b*exp(i*phi)-1)*c*exp(i*theta) ) . abs()
> > plot3d(f, (theta,0,pi), (phi,0,pi))
> >
> > No matter how I try to do this, even if I explicitly write out the
> > complex conjugates of each element, I get what for me is a record-length
> > screed of error stuff ending in 'TypeError: unable to coerce to a real
> > number', originating in the command 'plot3d(...etc...)'. I have attached
> > a text file with the full output of one of my attempts.
> >
> > I can see that in a way I am asking a lot of the interpreter; but then
> > again I feel I have explicitly made the thing real by the time it gets
> > to be an input for the plot3d function.
> >
> > Is there any way around this, or do I have to start writing complexes as
> > a+bi etc and do it the hard way?
> >
> > Many thanks
> >
> > Gary
>
> The problem is actually in the conversion of your function to a
> fast_float() version of the function. Apparently, it fails for symbolic
> "complex" functions (which are not really complex) even in this trivial
> example:
>
> f(theta, phi) = (theta + i * phi).abs()
> ff = fast_float(f, 'theta', 'phi')
>
> One trivial workaround is to define your function to be a python
> function. Somehow, it works. :)
>
> def f(theta,phi): return ( (a*exp(i*theta)-1)*d*exp(i*phi) -
> (b*exp(i*phi)-1)*c*exp(i*theta) ) . abs()
>
> plot3d(f, (theta, 0, pi), (phi, 0, phi))
>
>
>
--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.