2
$\begingroup$

After looking for an answer for 2 hours I give up and hope someone can help me out:

I have the following expression:

expr={0., 298.867 (0. + 0.0100379 HeavisideTheta[0]), 221.406 (0.0100379 \
+ 0.00903316 HeavisideTheta[0]), 3.12807, 121.51 (0.0190711 + \
0.0164595 HeavisideTheta[0]), 90.0171 (0.0355306 + 0.011109 \
HeavisideTheta[0]), 66.6863 (0.0466395 + 0.0149956 \
HeavisideTheta[0]), 49.4024 (0.0616351 + 0.0202419 \
HeavisideTheta[0]), 36.5982 (0.081877 + 0.0546474 HeavisideTheta[0]), \
3.70154, 20.0855 (0.136524 + 0.0995741 HeavisideTheta[0]), 14.8797 \
(0.236099 + 0.0672055 HeavisideTheta[0]), 11.0232 (0.303304 + \
0.090718 HeavisideTheta[0]), 3.21765, 2.38369, 4.48169 (0.394022 + \
0.44626 HeavisideTheta[0]), 3.32012 (0.840282 + 0.602388 \
HeavisideTheta[0]), 3.5484, 1.82212 (1.44267 + 0.548812 \
HeavisideTheta[0]), 1.34986 (1.99148 + 1.48164 HeavisideTheta[0]), 1. \
(3.47312 + 1. HeavisideTheta[0]), 3.31377, 2.4549, 1.81863, 1.34728, \
0.998088, 0.739402, 0.547762, 0.405792, 0.300618, 0.222703, 0.164983, \
0.122222, 0.0905445, 0.067077, 0.0496919, 0.0368126, 0.0272715, \
0.0202032, 0.0149669, 0.0110878};

in which I want to replace "HeavisideTheta" with "UnitStep". I'm not sure what I am doing wrong, I tried:

expr /. x_String /; StringMatchQ[x, "HeavisideTheta*"] -> "UnitStep"

which normally works on lists of strings, but does not work here. So I tried to convert it to a string and try again

expr2 = ToString@expr;
 expr2 /. x_String /; StringMatchQ[x, "HeavisideTheta*"] -> "UnitStep"

doesn't work either.

expr /. "HeavisideTheta"->"UnitStep"

also doesn't work. What am I doing wrong?

$\endgroup$
4
  • 1
    $\begingroup$ expr /. HeavisideTheta->UnitStep $\endgroup$
    – ZaMoC
    Commented Apr 16, 2017 at 23:33
  • 1
    $\begingroup$ Like Jenny_mathy says, you should use expr /. HeavisideTheta -> UnitStep since you have a list of expressions, not a list of strings. expr2 is a string, not a list of strings. Therefore in that case you need to use StringReplace to make replacements, not ReplaceAll (/.). $\endgroup$
    – C. E.
    Commented Apr 16, 2017 at 23:35
  • $\begingroup$ oh ok, I didn't figure that out ;) $\endgroup$
    – holistic
    Commented Apr 16, 2017 at 23:39
  • 1
    $\begingroup$ even better just do HeavisideTheta[0]->1 ( or 1/2 or whatever you want it to be ) $\endgroup$
    – george2079
    Commented Apr 17, 2017 at 17:48

1 Answer 1

3
$\begingroup$

the answer is

expr /. HeavisideTheta -> "UnitStep"
$\endgroup$
3
  • $\begingroup$ Thank you! I tried a lot but didn't figure out to just remove the quotation marks ;) $\endgroup$
    – holistic
    Commented Apr 16, 2017 at 23:38
  • $\begingroup$ Does @holistic want expr /. HeavisideTheta -> "UnitStep" or expr /. HeavisideTheta -> UnitStep? $\endgroup$
    – jjc385
    Commented Apr 17, 2017 at 6:06
  • $\begingroup$ I believe that this answer is clear. But you can try both and see some interesting results $\endgroup$
    – ZaMoC
    Commented Apr 17, 2017 at 8:36

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.