Ask Your Question
1

Substitute expressions with cos and sin

asked 2015-08-25 01:18:52 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I'm trying to simplify a symbolic expression obtained from sage integration. It contains terms of cos(theta)^2sin(theta)^2 and many others. I wanted to collect the coefficients of cos(theta)^2sin(theta)^2 and used subs_expr for this purpose. Here's a simplified version of what I'm trying to do:

var('theta,x,Psi')
y(theta)=cos(theta)^2*sin(theta)^2*cos(Psi)
y.subs_expr(cos(theta)^2*sin(theta)^2==x)

The result I got was "theta |--> cos(Psi)cos(theta)^2sin(theta)^2", not the expected "x*cos(Psi)". How can I get my expected result?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-08-25 15:55:57 +0200

kcrisman gravatar image

Half of your question is easier to answer. I bet if you do

var('theta,x,Psi')
y=cos(theta)^2*sin(theta)^2*cos(Psi)
y.subs_expr(cos(theta)^2*sin(theta)^2==x)

you won't get the theta |--> bit. That is because you are defining a function, not just an expression, in your example.

For substituting more advanced expressions, you will probably have to use wildcards. Note that

sage: y.subs_expr(cos(theta)^2==x)
x*cos(Psi)*sin(theta)^2

works; it's the fact that your expression isn't just one thing, but a product, that probably messes things up.

sage: y.subs({cos(theta)^2*sin(theta)^2*w0:x*w0})
x*cos(Psi)

but keep in mind that for your more complex expression you may need to have a more complicated use of wildcards. Good luck!

edit flag offensive delete link more

Comments

1

Thank you very much for you suggestions.

For people have similar needs as mine, I found maxima.fullratsubst did the job.

Liang gravatar imageLiang ( 2015-08-26 04:56:30 +0200 )edit

Yes, Maxima has a lot of methods of this type - great that you found this!

kcrisman gravatar imagekcrisman ( 2015-08-27 03:41:36 +0200 )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

Stats

Asked: 2015-08-25 01:18:52 +0200

Seen: 561 times

Last updated: Aug 25 '15