I have

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

enter image description here

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

Have fun!

| improve this answer | |

One way might be

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]

Mathematica graphics

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

| improve this answer | |
  • $\begingroup$ Thanks, that's what I was looking for. What do you mean that I would have to release the hold to use the answer? $\endgroup$ – enea19 Mar 22 '19 at 2:24
  • $\begingroup$ @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. $\endgroup$ – Nasser Mar 22 '19 at 2:28
  • $\begingroup$ 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. $\endgroup$ – enea19 Mar 22 '19 at 2:41
  • $\begingroup$ You could use Defer instead of HoldForm $\endgroup$ – Alrubaie Mar 22 '19 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.