ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 04 Oct 2017 04:39:32 -0500How to take partial derivative of abstract/unknown function?http://ask.sagemath.org/question/39029/how-to-take-partial-derivative-of-abstractunknown-function/I have a function `f(x)` that I do not want to be expanded but wish to evaluate the partial derivative of `g(x,f(x),...)` with respect to `x`, I can not figure out how to declare the function and indicate it is a function of x without an explicit definition.
Code example:
var("x")
f = ??? # how do I define this?
g = x * f(x)
g.diff(x)
Expected output:
x * f'(x) + f(x)Wed, 04 Oct 2017 04:15:39 -0500http://ask.sagemath.org/question/39029/how-to-take-partial-derivative-of-abstractunknown-function/Answer by wrenoud for <p>I have a function <code>f(x)</code> that I do not want to be expanded but wish to evaluate the partial derivative of <code>g(x,f(x),...)</code> with respect to <code>x</code>, I can not figure out how to declare the function and indicate it is a function of x without an explicit definition.</p>
<p>Code example:</p>
<pre><code>var("x")
f = ??? # how do I define this?
g = x * f(x)
g.diff(x)
</code></pre>
<p>Expected output:</p>
<pre><code>x * f'(x) + f(x)
</code></pre>
http://ask.sagemath.org/question/39029/how-to-take-partial-derivative-of-abstractunknown-function/?answer=39030#post-id-39030I found an example in the docs after asking: [Solving Differential Equations](http://doc.sagemath.org/html/en/tutorial/tour_algebra.html#solving-differential-equations)
Applying to the example given in the question though:
var("x")
f = function("f")(x)
g = x * f
g.diff(x)
Output:
x*diff(f(x), x) + f(x)Wed, 04 Oct 2017 04:39:32 -0500http://ask.sagemath.org/question/39029/how-to-take-partial-derivative-of-abstractunknown-function/?answer=39030#post-id-39030