1 | initial version |
You have (i) not to use the same name for the function R
and the expression R(x)
, (ii) to make Rsol
be a callable symbolic expression (i.e. replace Rsol
by Rsol(x)
) and (iii) to use substitute_function
for replacing R
by Rsol
. Here is the full code:
sage: var('Rq,k,K')
(Rq, k, K)
sage: M = function('M')
sage: R = function('R')
sage: de2 = diff(R(x), x) == -K*(R(x) - Rq)
sage: de1 = diff(M(x), x) == -k*(M(x) - R(x))
sage: Rsol(x) = desolve(de2.subs(k=1,K=2,Rq=20), R(x), ics=[0,15])
sage: Rsol(x)
5*(4*e^(2*x) - 1)*e^(-2*x)
sage: de1.subs(k=1).substitute_function(R, Rsol) # to check that the substitution works
diff(M(x), x) == 5*(4*e^(2*x) - 1)*e^(-2*x) - M(x)
sage: Msol(x) = desolve(de1.subs(k=1).substitute_function(R, Rsol), M(x))
sage: Msol(x)
(_C + 5*e^(-x) + 20*e^x)*e^(-x)
The symbol _C
stands for an arbitrary constant.