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.Sat, 04 Jan 2020 21:10:03 +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?asgerSat, 04 Jan 2020 21:10:03 +0100https://ask.sagemath.org/question/49362/A simple problem related to symbolic calculationhttps://ask.sagemath.org/question/26982/a-simple-problem-related-to-symbolic-calculation/Could anyone let me know how you can define a variable as some function of another variable without specific definition? For example, how can you define theta as some function of x and then differentiate the 'sin(theta)' by x?
The following is my code that doesn't work. I couldn't find how to fix it in reference manuals. Any help will be appreciated.
var('theta, y, f')
y=sin(theta) ; theta=f(x);
y.derivative(x)Nownuri1Sat, 30 May 2015 14:15:05 +0200https://ask.sagemath.org/question/26982/Differentiating Complex Conjugated Functionshttps://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/This is primarily a question of understanding the syntax of some output although there might be a bug hidden underneath. Consider the following code:
sage: var('x,t')
sage: q = function('q',x,t)
sage: f = q*q.conjugate()
sage: print f.derivative(x,1)
q(x, t)*D[0](conjugate)(q(x, t))*D[0](q)(x, t) + conjugate(q(x,t))*D[0](q)(x, t)
The answer is supposed to be $d/dx(q\bar{q}) = q_x \bar{q} + q \bar{q}_x$. The second term in the Sage output is correct but I'm having trouble deciphering the first term. Any thoughts?
I think I can narrow down the differences even further. Check it out:
sage: print q.conjugate().derivative(x,1)
D[0](conjugate)(q(x, t))*D[0](q)(x, t)
sage print q.derivative(x,1).conjugate()
conjugate(D[0](q)(x, t))
The independence of order isn't the issue: $q = u + iv$ means that $q_x = u_x + iv_x$, $\bar{q} = u - iv$. So $\bar{q_x} = u_x - iv_x$ and $(\bar{q})_x = (u - iv)_x = u_x - iv_x$.cswierczTue, 30 Nov 2010 16:18:04 +0100https://ask.sagemath.org/question/7780/why is symbolic comparison so slow?https://ask.sagemath.org/question/7642/why-is-symbolic-comparison-so-slow/I tried to write a little differentiatior:
from operator import add, mul, pow
def mydiff(s,x=x):
if x not in SR(s).variables():
return 0
elif s == x:
return 1
elif s == log(x):
return 1/x
elif s == sin(x):
return cos(x)
elif s == cos(x):
return -sin(x)
elif s == tan(x):
return 1+tan(x)^2
elif s == arcsin(x):
return 1/sqrt(1-x^2)
elif s == arctan(x):
return 1/(1+x^2)
op = s.operator()
ops = s.operands()
if op == pow and ops[0]==x and ops[1]._is_numeric():
return ops[1]*ops[0]^(ops[1]-1)
elif op == add:
return mydiff(ops[0]) + mydiff(reduce(op,ops[1:]))
elif op == mul:
f = ops[0]; g = reduce(mul,ops[1:])
return g*mydiff(f) + f*mydiff(g)
elif len(ops)==1:
return mydiff(ops[0],x)*mydiff(op(x),x).subs(x=ops[0]))
one my one year old macbook i need to wait more than 17 second to get the following answer
%time mydiff(sum(k*x^k,k,0,10))
CPU times: user 12.39 s, sys: 0.78 s, total: 13.17 s
Wall time: 17.49 s
100*x^9 + 81*x^8 + 64*x^7 + 49*x^6 + 36*x^5 + 25*x^4 + 16*x^3 + 9*x^2 + 4*x + 1
why does it _that_ long?Philipp SchneiderThu, 26 Aug 2010 20:55:27 +0200https://ask.sagemath.org/question/7642/