# Keep element of formula as it is

I have

ClearAll["Global*"];
de = f''[y] - (n^2 \[Pi]^2)/(4 a^2) f[y];
DSolve[de == -q/S (4/(n \[Pi] b))(-1)^((n - 1)/2), f[y], y]


and I would like the $$(-1)^{(n - 1)/2}$$ to be kept as it is in the solution, without using $$i$$. I remember that there is a way to do this but I forgot what the command is.

Try this:

de = f''[y] - (n^2 π^2)/(4 a^2) f[y];
DSolve[de == -q/S (4/(n π b)) (-1)^((n - 1)/2), f[y], y] /.
Times[Complex[0, -16], Power[Complex[0, 1], n_], a__] -> (HoldForm[-1])^((n + 1)/2)*a


As soon as you want to remove the HoldForm, apply ReleaseHold to the expression.

Have fun!

One way might be

ClearAll["Global*"];
de = f''[y] - (n^2 Pi^2)/(4 a^2) f[y];
myTerm = HoldForm[(-1)^((n - 1)/2)];
DSolve[de == -q/S (4/(n Pi b)) myTerm, f[y], y]


You'd have to release the hold to use the answer though

• Thanks, that's what I was looking for. What do you mean that I would have to release the hold to use the answer? – enea19 Mar 22 '19 at 2:24
• @enea19 I mean later on, if you want to use the solution for anything that require evaluations, such as plotting or getting numerical values or any other type of computation using the solution, you need to release the Hold on that term so that Mathematica can evaluate it. – Nasser Mar 22 '19 at 2:28
• Otherwise Mathematica will keep it as $(−1)^{(n−1)/2}$ forever? It's not necessarily a bad thing for the derivation that I have to do since I don't want $i$s but thanks for the warning. – enea19 Mar 22 '19 at 2:41
• You could use Defer instead of HoldForm – Alrubaie Mar 22 '19 at 18:54