Dear All,

I would like to take the derivative symbolically of a function but it 
doesn't seem to work. Basically W and S are matrices, Z=f(W,S) and 
loglikelihood=f(eta,Z). I would like the partial derivatives of the 
loglikelihood wrt eta and W_ij. It works for eta but not the W_ij. Here is 
the code

n = 3
T = 5
eta = sympy.Symbol('eta')
W = sympy.MatrixSymbol('W', n, n)
S = sympy.MatrixSymbol('S',n,T)
def detdyn(s,w):
    '''Z if a function of S and W'''
    f = w*s
    f_average = sympy.HadamardProduct(f, s)
    f_average = sympy.ones(1,f_average.shape[0]) * f_average #row sum
    #compute coefficients of Z
    for r in range(T):
        c.col_op(r, lambda i,j: i / f_average[0, r])
    z = sympy.HadamardProduct(c,s)
    return z
Tk = S.shape[1] #length of the data
Zk = detdyn(S,W)[:,:-1] #compute the deterministic dynamics
Sk = S[:,1:] #drop first observation
Sl = sympy.IndexedBase("Sk")
Zl = sympy.IndexedBase("Zk")
i, t = sympy.symbols('i t', cls=sympy.Idx)
0, 2)),(t, 0, Tk-1))

For example 

Sum(0, (i, 0, 2), (t, 0, 4))
which is not correct.

What am I doing wrong?

Thank you,

You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

Reply via email to