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, 09 Nov 2015 14:48:26 +0100Substituting derivatives in Taylor expansionshttps://ask.sagemath.org/question/30590/substituting-derivatives-in-taylor-expansions/Within Taylor expansions, as well as in results of 'Derivative'- operations, derivatives are marked by symbol "D[ ]" . I want to substitute them by other symbolic expressions/functions in order to get the usual presentation of derivative symbols via Latex. The following testprogram demonstrates that derivatives triggered by the "derivative"-operation can indeed be substituted by user-defined symbols, but not derivatives in Taylor expansions.
x,x_0=var("x,x_0")
a_4=var('a_4',latex_name='a_4')
a_5=var('a_5',latex_name='a_5')
T_e=function('T_e',nargs=1)
dt1=function('dt1',nargs=1)
dt2=function('dt2',nargs=1)
dTedx=var('dTedx',latex_name='\\frac{\operatorname{d}{T_e}}{\operatorname{d}x}')
type(T_e)
dt1=T_e(x).derivative(x)
print'dt1:',dt1
dt2=T_e(x_0).derivative(x_0)
print'dt2:',dt2
a3(x)=a_4+a_5*T_e(x)
print 'a3(x):',a3(x)
da3=a3(x).derivative(x)
print 'da3:', da3
print '### After a "derivative"-operation, substituting dt1 by dTedx works:'
da4=da3.subs(T_e(x).derivative(x)==dTedx)
print 'da4:',da4
ata=a3(x).taylor(x,x_0,1)
print 'Taylor series ata:',ata
print '### After Taylor expansion, substituting dt2 by dTedx does not work:'
atb=ata.subs(T_e(x_0).derivative(x_0)==dTedx)
print 'Taylor series atb:',atb
I run this program within In a SAGE6.8 notebook-session.
The output is:
dt1: D[0](T_e)(x)
dt2: D[0](T_e)(x_0)
a3(x): a_5*T_e(x) + a_4
### After a "derivative"-operation, substituting dt1 by dTedx works:
da3: a_5*D[0](T_e)(x)
da4: a_5*dTedx
### After Taylor expansion, substituting dt2 by dTedx does not work:
Taylor series ata: a_5*(x - x_0)*D[0](T_e)(x_0) + a_5*T_e(x_0) + a_4
Taylor series atb: a_5*(x - x_0)*D[0](T_e)(x_0) + a_5*T_e(x_0) + a_4
What is the reason for this difference?
Maybe, I merely must access the derivative expression within a Taylor expansion in a different way.
Thus: which is the correct way to do this?
bekalphMon, 09 Nov 2015 14:48:26 +0100https://ask.sagemath.org/question/30590/