Hi again
the following is driving me absolutely nuts. I thought i had implemented
all of the previous lessons you guys have taught me, but no matter how I
re-wire this I cannot get it to work. The function f works fine btw, as a
standalone function. But the minimize thing gives me all sorts of errors
depending on how i attempt to use it:
vs = VectorSpace(CC,2)
u = vs([1+I,1-I])
v = vs([3-2*I,6])
vars = var('t')
def f(t): return (vs(u-exp(I*t)*v)).norm(2)
minimize( f , [0] )
Sorry as always if I am missing something obvious but I really don't get
this!!
Thanks, as ever
Gary
On Wednesday, April 17, 2013 12:09:43 PM UTC+1, P Purkayastha wrote:
>
> 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 [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.