Ask Your Question
0

factor symbolic expression

asked 2021-04-25 16:47:57 +0100

Cyrille gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-04-25 17:33:02 +0100

Max Alekseyev gravatar image

Adding parentheses does the job:

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

edit flag offensive delete link more

Comments

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.

Cyrille gravatar imageCyrille ( 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

Max Alekseyev gravatar imageMax Alekseyev ( 2021-04-25 18:30:58 +0100 )edit

Thanks it works

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

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-25 16:47:57 +0100

Seen: 66 times

Last updated: Apr 25