Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Substitution of an indexed variable in an expression

Until a certain stage of my computation, I do not need indices in my work. Then I want to substitute indexed variables

x,y,p,q=SR.var('x, y, p, q')
A=matrix(SR,2,2,[x,-y,-x,0])
B=matrix(SR,2,2,[-x,y,x,0])
pp = vector(SR,[p, 1-p])
qq = vector(SR,[q, 1-q])
EGe0 = (pp*A*qq).collect(p)
EGp0 = (pp*B*qq).collect(q)
p = var("p", n=10, latex_name='\\overline{p}')
EGe0 = (pp*A*qq).collect(p).substitute_expression(p==p[0])
show(EGe0)

But I certainly have made an error. (I also tried .subs())