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.Wed, 27 Jul 2016 15:36:22 +0200Detecting highest order derivative of a function in an equationhttps://ask.sagemath.org/question/34243/detecting-highest-order-derivative-of-a-function-in-an-equation/ I am working with some code that generates an equation with a number of derivatives. I do not know the order of the derivatives or the order. If I was working with something algebraic, for example:
a, b, c = var('a,b,c')
eqn = a**2 + 3*b + c
I could use something like
coeffs = eqn.coefficients(a)
highest_order = coeffs[-1][1]
to find out the highest order of `a`. It would also be okay if i could figure out the order of every derivative of a given function in an equation. I can do this if I know before-hand what the order of the derivative is
function('f')
eqn += f(a,b,c).diff(a,b)
eqn.find(f(a,b,c).diff(a,b))
and see that in fact that derivative is there somewhere. But what I really want, is for
eqn = f(a,b,c).diff(a,b) + b*f(a,b,c).diff(b,3) + c
to have something that (a) tells me 'eqn has `[D[0,1](f)(a,b,c), D[1,1,1](f)(a,b,c)]`' or, (b) 'the highest order derivative of `eqn` is `D[1,1,1](f)(a,b,c)`'. Tue, 26 Jul 2016 22:41:17 +0200https://ask.sagemath.org/question/34243/detecting-highest-order-derivative-of-a-function-in-an-equation/Comment by calc314 for <p>I am working with some code that generates an equation with a number of derivatives. I do not know the order of the derivatives or the order. If I was working with something algebraic, for example:</p>
<pre><code>a, b, c = var('a,b,c')
eqn = a**2 + 3*b + c
</code></pre>
<p>I could use something like</p>
<pre><code>coeffs = eqn.coefficients(a)
highest_order = coeffs[-1][1]
</code></pre>
<p>to find out the highest order of <code>a</code>. It would also be okay if i could figure out the order of every derivative of a given function in an equation. I can do this if I know before-hand what the order of the derivative is</p>
<pre><code>function('f')
eqn += f(a,b,c).diff(a,b)
eqn.find(f(a,b,c).diff(a,b))
</code></pre>
<p>and see that in fact that derivative is there somewhere. But what I really want, is for</p>
<pre><code>eqn = f(a,b,c).diff(a,b) + b*f(a,b,c).diff(b,3) + c
</code></pre>
<p>to have something that (a) tells me 'eqn has <code>[D[0,1](f)(a,b,c), D[1,1,1](f)(a,b,c)]</code>' or, (b) 'the highest order derivative of <code>eqn</code> is <code>D[1,1,1](f)(a,b,c)</code>'. </p>
https://ask.sagemath.org/question/34243/detecting-highest-order-derivative-of-a-function-in-an-equation/?comment=34249#post-id-34249`eqn.operands()` comes close to (a). But, it will still take some work to get what you want.Wed, 27 Jul 2016 15:36:22 +0200https://ask.sagemath.org/question/34243/detecting-highest-order-derivative-of-a-function-in-an-equation/?comment=34249#post-id-34249