Ask Your Question

How to rearrange terms in an expression

asked 2011-01-16 22:35:34 +0200

mouse gravatar image

updated 2011-01-16 22:55:51 +0200

Mike Hansen gravatar image

I'm totally new to Sage. I was hoping I could use it for simple and complex application problems I run into at work. For example the relationship between flow rate, Q, and pressure drop, dP, for flow of a powerlaw fluid (m, n) in a cylindrical tube (L, R) is:

Q = (pi*R^3/((1/n)+3))*(Tau/m)^(1/n)

So I want to rearrange this expression for dP in terms of Q, m, n, L, R so I can then compute a table of results, plot dP versus Q etc. Now of course I can do the rearrangement by hand with pen and paper (or in my head on better days) but I was hoping that using the Sage notebook I could work through the rearrangement and thus have an digital record of the transformation so that others can follow along. However in all the hours of reading and watching tutorials, I have yet to see this simple process in action.

So far in my sage book I have:

Q, L, R, m, n, dP = var("Q, L, R, m, n, dP")
Tau = dP/(2*L/R)
Q = (pi*R**3/((1/n)+3))*(Tau/m)**(1/n)

(Note that the preview doesn't show the power symbol **, hope it appears in the posted question)

Is there a method, say, Q.rearrange(dP) that yields dP = f(Q, L, R, m, n)? If not, how do I write the intermediate steps in sage speak to give this expression?

Sorry if this is such a basic question.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-01-17 05:34:05 +0200

mouse gravatar image

updated 2011-01-19 18:17:48 +0200

OK, after more googling I found a link to manipulating symbolic expressions which seems to cover what I want. Here'tis for any others that may be interested.

Good point Evgeny! So here's a simple example


assume(z, 'integer')

eqn = x == y**z

solve(eqn, y)

Note: this will fail without the assume statement (see this response from kcrisman ).

edit flag offensive delete link more


Can you be more specific about what commands did what you wanted? You should be able to edit your own post. Anyway, that would help others who find this post and want to see the specific details so they can imitate them.

kcrisman gravatar imagekcrisman ( 2011-01-17 12:27:51 +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


Asked: 2011-01-16 22:35:34 +0200

Seen: 2,270 times

Last updated: Jan 19 '11