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.Sun, 05 Jan 2020 00:34:29 +0100symbolic differentiation of unknown functionhttps://ask.sagemath.org/question/49362/symbolic-differentiation-of-unknown-function/I want to do some formal calculus with unknown functions
for the purpose of solving differential equations.
Say `F(t) = v(t)*t^2`, where `v` is an unknown differentiable function.
Then I would like to declare `v` as such and be able to get
`F.diff(t) = 2*t*v+t^2*v.diff(t)`
It is similar to [Ask Sage question 8822](https://ask.sagemath.org/question/8822)
but the solution does not seem to work anymore, as `function()` takes
only one argument and not 2 as in the description.
Anyone know what the syntax is in 8.9? Or in 9.0, when that becomes available?Sat, 04 Jan 2020 21:10:03 +0100https://ask.sagemath.org/question/49362/symbolic-differentiation-of-unknown-function/Comment by slelievre for <p>I want to do some formal calculus with unknown functions
for the purpose of solving differential equations.</p>
<p>Say <code>F(t) = v(t)*t^2</code>, where <code>v</code> is an unknown differentiable function.</p>
<p>Then I would like to declare <code>v</code> as such and be able to get</p>
<p><code>F.diff(t) = 2*t*v+t^2*v.diff(t)</code></p>
<p>It is similar to <a href="https://ask.sagemath.org/question/8822">Ask Sage question 8822</a>
but the solution does not seem to work anymore, as <code>function()</code> takes
only one argument and not 2 as in the description.</p>
<p>Anyone know what the syntax is in 8.9? Or in 9.0, when that becomes available?</p>
https://ask.sagemath.org/question/49362/symbolic-differentiation-of-unknown-function/?comment=49367#post-id-49367Note: I updated the answer to [Ask Sage question 8822](https://ask.sagemath.org/question/8822).Sun, 05 Jan 2020 00:34:29 +0100https://ask.sagemath.org/question/49362/symbolic-differentiation-of-unknown-function/?comment=49367#post-id-49367Answer by slelievre for <p>I want to do some formal calculus with unknown functions
for the purpose of solving differential equations.</p>
<p>Say <code>F(t) = v(t)*t^2</code>, where <code>v</code> is an unknown differentiable function.</p>
<p>Then I would like to declare <code>v</code> as such and be able to get</p>
<p><code>F.diff(t) = 2*t*v+t^2*v.diff(t)</code></p>
<p>It is similar to <a href="https://ask.sagemath.org/question/8822">Ask Sage question 8822</a>
but the solution does not seem to work anymore, as <code>function()</code> takes
only one argument and not 2 as in the description.</p>
<p>Anyone know what the syntax is in 8.9? Or in 9.0, when that becomes available?</p>
https://ask.sagemath.org/question/49362/symbolic-differentiation-of-unknown-function/?answer=49366#post-id-49366Here is how to do it.
Works with the following version of Sage.
sage: version()
'SageMath version 9.0, Release Date: 2020-01-01'
Declare variable `t` and function `v`,
and define function `F` in terms of those:
sage: t = SR.var('t')
sage: v = function('v')
sage: F(t) = v(t)*t^2
Derivative of the function:
sage: F.diff(t)
t |--> t^2*diff(v(t), t) + 2*t*v(t)
Derivative of the expression:
sage: F(t).diff(t)
t^2*diff(v(t), t) + 2*t*v(t)
Sun, 05 Jan 2020 00:30:27 +0100https://ask.sagemath.org/question/49362/symbolic-differentiation-of-unknown-function/?answer=49366#post-id-49366