0
$\begingroup$

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

g2''[y]

where I would rather it return

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

Thank you.

$\endgroup$

1 Answer 1

3
$\begingroup$

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}]

Gives

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$

 InputForm[%]

Mathematica graphics

$\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.