Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Define vector valued function of a vector of symbolic variables?

I have a gradient where each component may have a different number of symbolic arguments and get the following error when I run:

gradL
(gradL[0]).arguments()
(gradL[1]).arguments()
(gradL[2]).arguments()
s=[3,.5,.3]
(gradL[0])(s)
(gradL[1])(
s)
(gradL[2])(*s)

(lam0(x1 - 1.00000000000000) - log(x0) + log(-x0 + 1), lam0x0 - log(x1) + log(-x1 + 1), x0*x1 - x0 + 0.500000000000000)
(lam0, x0, x1)
(lam0, x0, x1)
(x0, x1)
-2.10000000000000
2.34729786038720
Error in lines 8-8
Traceback (most recent call last): File "/projects/5511fe15-8085-4d1d-bdc7-c6bf6c99e693/.sagemathcloud/sage_server.py", line 865, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "sage/symbolic/expression.pyx", line 4382, in sage.symbolic.expression.Expression.__call__ (build/cythonized/sage/symbolic/expression.cpp:24669) File "sage/symbolic/ring.pyx", line 760, in sage.symbolic.ring.SymbolicRing._call_element_ (build/cythonized/sage/symbolic/ring.cpp:8970) ValueError: the number of arguments must be less than or equal to 2

I need to be able to to be able to define this as a vector valued function of a vector so that I can evaluate it using the entire argument set (lam0, x0, x1) where the missing arguments are ignored for the corresponding component. This is so I can def a function for scipy.optimize like:

def F(s):
  tmp=[]
  for ii in range(len(gradL)):
    tmp.append((gradL[ii])(*s))
  return tmp
ssoln = scipy.optimize.broyden1(F, [.5,.5,.5], f_tol=1e-14)

I can't figure out how to accomplish this. Thanks for any help in advance.

-Steve