ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 01 Oct 2018 10:07:21 -0500sum and Substitutehttp://ask.sagemath.org/question/43804/sum-and-substitute/Hi
why Ds (like D ) does not give a numerical value ?
fs_d=r"!n \triangleq n! \sum_{i = 0}^{n}\frac{(-1)^i}{i!}"
#https://en.wikipedia.org/wiki/Derangement
forget()
var('n,l')
assume(l, 'integer')
assume(l>0)
assume(l, 'integer')
assume(n, 'integer')
assume(n>l)
assume(n, 'integer')
# Derangement
D=function('D')(n,l)
Dn=function('Dn')(n,l)
Dn=factorial(n)*sum(((-1)^l/factorial(l)),l,0,n)
D=factorial(7)*sum(((-1)^l/factorial(l)),l,0,7)
Ds=Dn.substitute({n:7})
show(LatexExpr(fs_d))
show('D : ',D)
show('Ds : ',Ds)
ortolljMon, 01 Oct 2018 10:07:21 -0500http://ask.sagemath.org/question/43804/Substitute expression for function in differential equationhttp://ask.sagemath.org/question/38130/substitute-expression-for-function-in-differential-equation/ This is related to [8293](https://ask.sagemath.org/question/8293/substitute-formal-function-by-an-expression-in-a-differential-equation/), but a lot has changed since then, so I wonder if there is a way to achieve this now.
Expanding on an example from [26114](https://ask.sagemath.org/question/26114/why-is-basic-arithmetic-disallowed-on-symbolic-functions/), I define a differential equation based on unevaluated functions and then want to substitute one of the functions (H) by an expression (T_s^2):
sage: var('T_s')
sage: B = function('B')(T_s)
sage: E = function('E')(T_s)
sage: H = function('H')(T_s)
sage: eq_B_TS = B == H/E
sage: eq1 = diff(eq_B_TS, T_s)
sage: eq1
diff(B(T_s), T_s) == -H(T_s)*diff(E(T_s), T_s)/E(T_s)^2 + diff(H(T_s), T_s)/E(T_s)
sage: eq1.subs(H == T_s^2)
diff(B(T_s), T_s) == -T_s^2*diff(E(T_s), T_s)/E(T_s)^2 + diff(H(T_s), T_s)/E(T_s)
I expected this output:
diff(B(T_s), T_s) == -T_s^2*diff(E(T_s), T_s)/E(T_s)^2 + 2*T_s/E(T_s)
However, the substitution was not carried out inside the differential. Is this a missing feature or a bug? Basically, I would like to be able to formulate general symbolic equations including differentials and integrals, and then insert explicit expressions for the different elements that would allow evaluation of the differentials and integrals. stanThu, 29 Jun 2017 16:12:29 -0500http://ask.sagemath.org/question/38130/Substitute expressions with cos and sinhttp://ask.sagemath.org/question/29349/substitute-expressions-with-cos-and-sin/ I'm trying to simplify a symbolic expression obtained from sage integration. It contains terms of cos(theta)^2*sin(theta)^2 and many others. I wanted to collect the coefficients of cos(theta)^2*sin(theta)^2 and used subs_expr for this purpose. Here's a simplified version of what I'm trying to do:
var('theta,x,Psi')
y(theta)=cos(theta)^2*sin(theta)^2*cos(Psi)
y.subs_expr(cos(theta)^2*sin(theta)^2==x)
The result I got was "theta |--> cos(Psi)*cos(theta)^2*sin(theta)^2", not the expected "x*cos(Psi)". How can I get my expected result?
LiangMon, 24 Aug 2015 18:18:52 -0500http://ask.sagemath.org/question/29349/