OK I have now uncovered another weird sage-python problem. I think I should
be the go-to guy to wreck otherwise perfectly healthy code :).

If you try to use the function minimize() with the python function @ppurka
defined above then you get the error

TypeError: g() takes exactly 2 arguments (1 given)


whereas if I try to do the minimize using a SAGE function as per my
original message, we get back to the same "coercion to real" problem. Here
is some dumb code to show the problem:

vars = var('x y')
def gg(x,y): return sin(x) + cos(y)
minimize(gg,[0,0])

gives the above error; whereas:

vars = var('x y')
gg = sin(x) + cos(y)
minimize(gg,[0,0])

works fine .... I cannot see anywhere in the reference manual where the
syntax for minimize() for python functions, should be different from that
for SAGE functions right?!

Kind regards

Gary

PS using SAGE 5.7 on VM version 4.2.10 on Windows 7 on an HP notebook


On Wed, Apr 17, 2013 at 11:11 AM, Gary McConnell <garymako...@googlemail.com
> wrote:

> Sorry - at ease ...
>
> If I name the plot PP or something then put just 'PP' in a different cell
> from its definition, it shows up fine.
>
> Thanks again for the help
>
> Kind regards
>
> Gary
>
>
> On Wed, Apr 17, 2013 at 10:39 AM, GaryMak <garymako...@googlemail.com>wrote:
>
>> 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 a topic in the
>> Google Groups "sage-support" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/sage-support/3mekDq5Stvk/unsubscribe?hl=en
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> sage-support+unsubscr...@googlegroups.com.
>> To post to this group, send email to sage-support@googlegroups.com.
>> Visit this group at http://groups.google.com/group/sage-support?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>

-- 
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 sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to