# How to use a rule and its derivative on an equation?

I generated a very simple rule that is of the type

{a -> 0,  a -> 0,  a -> 8/3*pi}


And I want to impose this set of rules on an equation. The problem is that in this equation there are some derived terms like a'. How can I use the rule directly by imposing its derivative where needed as well?

• Welcome to Mathematica S.E. To start: 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, since the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) consider accepting the answer, if any, that solves your problem, by clicking checkmark sign, 4) give help too, by answering questions in your areas of expertise.
– bmf
Feb 2 at 1:14
• You can do this also in the same way i.e. {a -> 0, a -> 0, a -> 8/3*pi, a'->value} Feb 2 at 5:06

Clear["Global*"]


Given rules like {a -> 0, a -> 0, a -> 8/3*Pi} you cannot take their derivative since everything is constant.

An example for which derivatives can be taken.

eqn = {a''[x] + 4 a[x] == 0, a == 1, a' == 4};


Rule:

sol = DSolve[eqn, a[x], x][]

(* {a[x] -> Cos[2 x] + 2 Sin[2 x]} *)


Derivatives:

der = NestList[D[#, x] &, sol, 2] // Flatten

(* {a[x] -> Cos[2 x] + 2 Sin[2 x],
a'[x] -> 4 Cos[2 x] - 2 Sin[2 x], a''[x] -> -4 Cos[2 x] -
8 Sin[2 x]} *)


Initial conditions:

ic = Most@der /. x -> 0

(* {a -> 1, a' -> 4} *)


Verification,

eqn /. der /. ic // Simplify

(* {True, True, True} *)


If you want to set derivatives of constants to zero you can write e.g.:

2 a + 3 a' + 4 a'' /. {Derivative[_][_] -> 0}
(* 2 a *)


However, if the derivatives have some values that you want to replace, you can write:

drule = {a' -> 11, a' -> 22, a' -> 33};
2 a + 3 a' + 4 a' /. drule
(* 198 + 2 a *)
`