Differentiating function with fluctuating number of variables
(Edit: I've changed the question somewhat - upon editing the code the problem seems to lie elsewhere.)
Let's say I have a vector space V of dimension n (which is variable) and a matrix M (also depending on n and other input), and I want to understand the derivative of the function v -> ||M*v|| at some vector v in V, and then evaluate it at tangent vectors.
As far as I can tell, the easiest way to do this is to use a symbolic vector v, then calculate ||M*v||, then take diff(), and then I can plug in a tangent vector.
So I would write something like
v = list(var('v_%d' % i) for i in range(1,n+1))
def f(*arg):
L = []
for var in arg:
L.append(var)
return (M*vector(L)).norm()
(which is clearly bad and going nowhere) but attempting something like this, diff(f) throws an error:
unable to convert <function f at 0x7f2b046c5b90> to a symbolic expression
Trying
f(*v) = (M*vector(v)).norm()
doesn't work either.
I can't replicate it, can you provide your code ? Or at least a working example that produces the issue.
Oops, I've changed the question - thank you very much.