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?
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 useStringReplace
to make replacements, notReplaceAll
(/.
). $\endgroup$HeavisideTheta[0]->1
( or1/2
or whatever you want it to be ) $\endgroup$