Ask Your Question
1

Converting expression to list of terms and back

asked 9 years ago

pircks gravatar image

Given an expression how would I convert it to a list, and how would I convert a list to an expression?

For example:

x * b * cos(x^3) * sin(b)+b * cos(x)+h * sin(x)

Would convert to:

[x * b * cos(x^3) * sin(b),b * cos(x),h * sin(x)]

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 9 years ago

slelievre gravatar image

The methods operator and operands for symbolic expressions are what you are looking for.

sage: b, h, x = var('b h x')
sage: expr = x * b * cos(x^3) * sin(b)+b * cos(x)+h * sin(x)
sage: expr.operator()
<function add_vararg at 0x10abe0aa0>
sage: expr.operands()
[b*x*cos(x^3)*sin(b), b*cos(x), h*sin(x)]
Preview: (hide)
link

Comments

How does this work for converting [bxcos(x^3)sin(b), bcos(x), h*sin(x)] back into an expression, say using addition?

NahsiN gravatar imageNahsiN ( 8 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: 9 years ago

Seen: 435 times

Last updated: Dec 28 '15