Hello I have some code that have terms that look like g2''[y] E^[n I x] where n is 0,1,2,... I would like for when n=0 for the E^[0 I x] terms to stay as E^[0 I x] and not be changed to one. For example, in symbolic calculations if I were to input into Mathematica

g2''[y] E^[0 I x]

it returns


where I would rather it return

g2''[y] E^[0 I x].

Thank you.


1 Answer 1


You can't do this without holding the expression, since Mathematica will automatically replace $e^{i 0 x}$ with $1$.

ClearAll[g, y, n, x];
Table[With[{n = n}, 
  g''[y] If[n == 0, HoldForm@Exp[n I x], Exp[n I x]]], {n, 0, 4}]


Mathematica graphics

But under the cover, $e^{i 0 x}$ is wrapped with HoldForm and it is stuck with it until you remove the hold, then it goes back to $1$


Mathematica graphics


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.