# factor symbolic expression

In the following code, if I add .collect(p) to the pp*A*qq in the before last expression, I have an error. Why ?

LE=LatexExpr
x,y,p,q=SR.var('x, y, p, q')
A=matrix(SR,2,2,[x,-x,-x,0])
B=matrix(SR,2,2,[-x,y,x,0])
show(LE(r"\boldsymbol{A} = "),A, LE(r"\,\,\,\,\,\text{et}\,\,\,\,\,"),LE(r"\boldsymbol{B} = "),B)
pp = vector(SR,[p, 1-p])
qq = vector(SR,[q, 1-q])
show(LE(r"\boldsymbol{p} = "),pp, LE(r"\,\,\,\,\,\text{et}\,\,\,\,\,"),LE(r"\boldsymbol{q} = "),qq)
EGe0 = pp*A*qq.collect(p)
show(LE(r"\mathbb{E}G_e^0 = "),EGe0)

edit retag close merge delete

Sort by ยป oldest newest most voted

EGe0 = (pp*A*qq).collect(p)

more

Thanks but I have an other problem y is not recognized as a variable. I don't undersand since itis decalred. I have tried without comas. But nothing work so I can't see the effect of the parenthesis.

( 2021-04-25 17:58:13 +0100 )edit

I'm not sure what problem you are talking about as your code runs without an issue at Sagecell: https://sagecell.sagemath.org/?q=fmhwan

( 2021-04-25 18:30:58 +0100 )edit

Thanks it works

( 2021-04-25 22:28:27 +0100 )edit