I have some expressions that involve the derivative of y(x)
with respect to x
. An example is below. I need to substitute x = 0
in these expressions, to get rid of the zero terms.
P: x*%e^x*y+%e^x*y-
%e^x*log(x+1)*('diff(y(x),x,2))-
%e^x*log(x+1)*('diff(y(x),x,1))-
(%e^x*('diff(y(x),x,1)))/(x+1);
But when I try
P, x = 0;
or
subst(x = 0, P);
I get the error
diff: variable must not be a number; found: 0
So it doesn't want to put x = 0
in diff(y(x), x)
. Is there any way I can substitute x = 0
for the occurrences of x
outside differentiation? The expressions I have are very complicated, so I really need to get rid of these terms that are 0.
at
represents the value of an expression, but it's careful to avoid substituting a literal value into an expression for which it isn't valid, such as diff
. From the problem statement:
(%i2) P: x*%e^x*y+%e^x*y-
%e^x*log(x+1)*('diff(y(x),x,2))-
%e^x*log(x+1)*('diff(y(x),x,1))-
(%e^x*('diff(y(x),x,1)))/(x+1);
2
x x x d
(%o2) x %e y + %e y - %e log(x + 1) (--- (y(x)))
2
dx
x d
%e (-- (y(x)))
x d dx
- %e log(x + 1) (-- (y(x))) - ---------------
dx x + 1
(%i3) at(P, x = 0);
!
d !
(%o3) y - -- (y(x))!
dx !
!x = 0
Just to clarify, aside from diff
, integrate
, and other expressions containing dummy variables, at
effectively just substitutes the literal value.
(%i4) at(sin(x) + cos(x), x = a);
(%o4) sin(a) + cos(a)
I see a problem with the original problem statement -- it contains both y
and y(x)
-- which makes it hard to substitute some actual function for y
later on. If it matters, you might want to use y(x)
throughout, or to say depends(y, x)
and then use y
throughout.