Ask Your Question
0

Substitution of an indexed variable in an expression

asked 2021-04-27 16:17:43 +0100

Cyrille gravatar image

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())

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-27 16:56:09 +0100

rburing gravatar image

Indeed, (pp*A*qq).collect(p) does not work because p now refers to the tuple containing the indexed variables, rather than the original p. So, use a different name for the tuple of indexed variables, like P:

P = var("p", n=10, latex_name='\\overline{p}')
EGe0 = (pp*A*qq).collect(p).subs(p==P[0])
show(EGe0)

Output: $${\left(2 q x + {\left(q - 1\right)} y\right)} {\overline{p}}_{0} - q x$$

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-04-27 16:17:43 +0100

Seen: 220 times

Last updated: Apr 27 '21