First time here? Check out the FAQ!

Ask Your Question
0

factor symbolic expression

asked 3 years ago

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)
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 3 years ago

Max Alekseyev gravatar image

Adding parentheses does the job:

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

Preview: (hide)
link

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 ( 3 years ago )

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 ( 3 years ago )

Thanks it works

Cyrille gravatar imageCyrille ( 3 years ago )

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: 3 years ago

Seen: 243 times

Last updated: Apr 25 '21