2
$\begingroup$

If I try to replace the function u0 and its derivatives by zero in the following examplary expression

expr = t HeavisideTheta[0.174 +φ] - 1651.2 u0[t, φ] + 3293.841 t Derivative[0, 1][u0][t, φ];
expr/.u0->(0&)
(*0. + t HeavisideTheta[0.174 + φ]*)

Mathematica gives an output 0.+....

My question: How can I avoid this zero part 0.+ in the output(without using Chop) ? Thanks!

$\endgroup$
3
$\begingroup$

Could you just add another replacement rule?

expr /. u0 -> (0&) /. 0. -> 0

t HeavisideTheta[0.174 + φ]

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks, unbelievable simple trick /.0. -> 0, but it works. $\endgroup$ – Ulrich Neumann Oct 29 '19 at 15:48
2
$\begingroup$

Try also this:

Map[Rationalize, expr, Infinity] /. u0 -> (0 &) // N

(* t HeavisideTheta[0.174 + φ]  *)
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks! expr /. u0 -> (0 &) // Rationalize works too! $\endgroup$ – Ulrich Neumann Oct 30 '19 at 7:50
  • $\begingroup$ @Ulrich Neumann Yes, this your version is even better. $\endgroup$ – Alexei Boulbitch Oct 30 '19 at 12:57
1
$\begingroup$

Not sure if this will cause other problem, but the following does work for your example:

Clear@u0
u0 /: u0[__] number_Real := 0
Derivative[__][u0] ^:= u0
expr
(* t HeavisideTheta[0.174 + φ] *)
| improve this answer | |
$\endgroup$
  • $\begingroup$ @xzcd Thanks, your first solution (comment SetPrecision[expr, Infinity] /. u0 -> (0 &) ) seems to be more reliable because it also solves the case expr=t HeavisideTheta[a + \[CurlyPhi]] - b u0[t, \[CurlyPhi]] + c t Derivative[0, 1][u0][t, \[CurlyPhi]] $\endgroup$ – Ulrich Neumann Oct 29 '19 at 13:02
  • $\begingroup$ @UlrichNeumann I removed that one because I think that method is somewhat similar to the Chop method. (It changes the numbers inside expr, too. ) To handle the new added example, you can again add a /. u0 -> (0 &) at the end of expr. $\endgroup$ – xzczd Oct 29 '19 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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