Ask Your Question
0

minimize_constrained for a one dimensional function

asked 2012-11-12 08:45:16 +0100

Mathmon gravatar image

Hello all,

I have a bit of a problem with the minimize_constrained function: When I call

minimize_constrained(lambda x: x^2, [lambda x: 1], 99.6)

I get a TypeError: iteration over a 0-d array (why?). If I call

minimize_constrained(lambda x: x^2, \
    [lambda x: vector({0:1,1:x}).inner_product(vector((0,0)))], 99.6)

I get a TypeError: unable to find a common ring for all elements. This seems to be the case because the the constraint function is sometimes called with a numpy.ndarray and at other times with a sage.modules.vector_real_double_dense.Vector_real_double_dense. In the first case I need to call float(x[0]), in the latter I can use x[0] directly.

Is it be possible to convert the data to sage vectors throughout the iterations or do I have to set up a handler to sanitize the input myself?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-05-27 23:00:32 +0100

mforets gravatar image

updated 2017-05-27 23:00:47 +0100

The function (func argument) passed to minimize_constrained can be either a symbolic function,

sage: x = var('x')
sage: minimize_constrained(x^2, [None], [99.6])
(0.0)

or a Python function whose argument is a tuple,

sage: minimize_constrained(lambda x: x[0]^2, [None], [99.6])
(0.0)

The type error in the OP is avoided passing the initial point as a list.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-11-12 08:45:16 +0100

Seen: 400 times

Last updated: May 27 '17