On 04/17/2013 07:05 PM, Gary McConnell wrote:
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

Hello Gary,

The minimize function takes in a function which has only *one* argument. That argument itself can be tuple or list. So, this very simple modification to your code works:

sage: def gg(x): return sin(x[0]) + cos(x[1])
sage: minimize(gg,[0,0])
Optimization terminated successfully.
         Current function value: -2.000000
         Iterations: 72
         Function evaluations: 139
(-1.5707636272, 3.14159570731)

  basu.

--
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