ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 17 Jan 2011 12:27:51 +0100How to rearrange terms in an expressionhttps://ask.sagemath.org/question/7880/how-to-rearrange-terms-in-an-expression/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. Sun, 16 Jan 2011 22:35:34 +0100https://ask.sagemath.org/question/7880/how-to-rearrange-terms-in-an-expression/Answer by mouse for <p>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:</p>
<pre><code>Q = (pi*R^3/((1/n)+3))*(Tau/m)^(1/n)
</code></pre>
<p>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. </p>
<p>So far in my sage book I have:</p>
<pre><code>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)
</code></pre>
<p>(Note that the preview doesn't show the power symbol **, hope it appears in the posted question)</p>
<p>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?</p>
<p>Sorry if this is such a basic question. </p>
https://ask.sagemath.org/question/7880/how-to-rearrange-terms-in-an-expression/?answer=11976#post-id-11976OK, 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.
http://www.sagemath.org/doc/reference/sage/symbolic/relation.html
Good point Evgeny! So here's a simple example
var('x,y,z')
assume(z, 'integer')
eqn = x == y**z
solve(eqn, y)
Note: this will fail without the assume statement (see this response from kcrisman http://ask.sagemath.org/question/318/failure-on-symbolic-solve ).Mon, 17 Jan 2011 05:34:05 +0100https://ask.sagemath.org/question/7880/how-to-rearrange-terms-in-an-expression/?answer=11976#post-id-11976Comment by kcrisman for <p>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.</p>
<p><a href="http://www.sagemath.org/doc/reference/sage/symbolic/relation.html">http://www.sagemath.org/doc/reference...</a></p>
<p>Good point Evgeny! So here's a simple example </p>
<p>var('x,y,z')</p>
<p>assume(z, 'integer')</p>
<p>eqn = x == y**z</p>
<p>solve(eqn, y)</p>
<p>Note: this will fail without the assume statement (see this response from kcrisman <a href="http://ask.sagemath.org/question/318/failure-on-symbolic-solve">http://ask.sagemath.org/question/318/...</a> ).</p>
https://ask.sagemath.org/question/7880/how-to-rearrange-terms-in-an-expression/?comment=22270#post-id-22270Can 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.Mon, 17 Jan 2011 12:27:51 +0100https://ask.sagemath.org/question/7880/how-to-rearrange-terms-in-an-expression/?comment=22270#post-id-22270