1
$\begingroup$

I generated a very simple rule that is of the type

{a[0] -> 0,  a[1] -> 0,  a[2] -> 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'[0]. How can I use the rule directly by imposing its derivative where needed as well?

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – bmf
    Feb 2, 2023 at 1:14
  • $\begingroup$ You can do this also in the same way i.e. {a[0] -> 0, a[1] -> 0, a[2] -> 8/3*pi, a'[0]->value} $\endgroup$
    – Dunlop
    Feb 2, 2023 at 5:06

2 Answers 2

2
$\begingroup$
Clear["Global`*"]

Given rules like {a[0] -> 0, a[1] -> 0, a[2] -> 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[0] == 1, a'[0] == 4};

Rule:

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

(* {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[0] -> 1, a'[0] -> 4} *)

Verification,

eqn /. der /. ic // Simplify

(* {True, True, True} *)
$\endgroup$
0
$\begingroup$

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

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

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

drule = {a[0]' -> 11, a[1]' -> 22, a[2]' -> 33};
2 a[0] + 3 a[1]' + 4 a[2]' /. drule
(* 198 + 2 a[0] *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.