# how can i define a matrix product like a summation

This post is a wiki. Anyone with karma >750 is welcome to improve it.

first, my mother tongue is not English but I try it, my problem is that if I define a symbolic matrix V such that,

var('V_11,V_12,V_13,V_21,V_22,V_23,V_31,V_32,V_33')

V = matrix(SR,3,3,[V_11,V_12,V_13,V_21,V_22,V_23,V_31,V_32,V_33])


and then I define

P = [V[a,k]*V[b,k]*V[a,j]*V[b,j] for k in [0,1,2] for j in  [0,1,2]]


But if I evaluate, for example

P(a=0,b=1)


but the code is not work can someone help me?

edit retag close merge delete

Sort by ยป oldest newest most voted

maybe this is what you want to do?

sage: var('V_11,V_12,V_13,V_21,V_22,V_23,V_31,V_32,V_33');
sage: V = matrix(SR,3,3,[V_11,V_12,V_13,V_21,V_22,V_23,V_31,V_32,V_33])
sage: P = lambda a, b : [V[a,k]*V[b,k]*V[a,j]*V[b,j] for k in [0,1,2] for j in  [0,1,2]]
sage: P(a=0, b=1)

[V_11^2*V_21^2,
V_11*V_12*V_21*V_22,
V_11*V_13*V_21*V_23,
V_11*V_12*V_21*V_22,
V_12^2*V_22^2,
V_12*V_13*V_22*V_23,
V_11*V_13*V_21*V_23,
V_12*V_13*V_22*V_23,
V_13^2*V_23^2]

more

Thank you so much this is exactly i want

( 2017-08-03 12:21:25 -0500 )edit