1
$\begingroup$

I would like to solve an ODE $-f'' + \left ( 1 - \frac{1}{k} \right )f = 0$ on the interval $(0, 1)$ where $k \in (0, 1)$ is a constant. I use the command

sol = DSolve[{- f''[x] + (1 - 1 / k) * f[x] == 0}, f[x], {x, 0, 1}];
sol = Assuming[k > 0 && k < 1, FullSimplify[sol]]

Mathematica returns

enter image description here

The expression $\sqrt{\frac{-1+k}{k}}$ does not make sense to me because $\frac{-1+k}{k} < 0$ for $k \in (0, 1)$. Could you elaborate on this issue?

$\endgroup$
9
  • 1
    $\begingroup$ The expression makes mich sense, because Sqrt[(-1+k)/k]->I /omega transforms the ode in a well known form omega^2 f''[x]+f[x]==0 $\endgroup$ Commented Dec 11, 2023 at 21:05
  • $\begingroup$ @UlrichNeumann Could you explain what Sqrt[(-1+k)/k]->I omega means? $\endgroup$
    – Akira
    Commented Dec 11, 2023 at 21:06
  • $\begingroup$ It's a simple substitution Sqrt[(-1+k)/k]=:I omega $\endgroup$ Commented Dec 11, 2023 at 21:08
  • $\begingroup$ You are using DSolve and not NDSolve. So writing {x, 0, 1} is not needed and does not do anything. Just write x. Do you know of a case where DSolve result was different when writing {x,from,to} vs. just x? I know of no such case. $\endgroup$
    – Nasser
    Commented Dec 11, 2023 at 21:37
  • 4
    $\begingroup$ To elaborate on what @UlrichNeumann said,$$e^{\pm \sqrt{(1-k)/k} x} = e^{\pm i \sqrt{(k-1)/k} x} = \cos \left( \sqrt{\frac{k-1}{k}} x \right) \pm i \sin \left( \sqrt{\frac{k-1}{k}} x \right)$$and if you choose complex values of $c_1$ and $c_2$ in your solution (specifically, $c_2 = c_1^*$) your solution becomes linear combination of a sine and a cosine. $\endgroup$ Commented Dec 11, 2023 at 22:12

2 Answers 2

3
$\begingroup$

I guess this is the form you are looking for...?

sol = DSolve[{-f''[x] + (1 - 1/k)*f[x] == 0}, f[x], {x, 0, 1}];
sol = First[f[x] /. Assuming[k > 0 && k < 1, FullSimplify[sol]]];
PowerExpand[ExpToTrig[sol], Assumptions -> 0 < k < 1];
Collect[%, {Cos[_], Sin[_]}, Factor]

(C[1] + C[2]) Cos[Sqrt[-1 + 1/k] x] + I (C[1] - C[2]) Sin[Sqrt[-1 + 1/k] x]

$$(c_1+c_2) \cos \left(x \sqrt{\frac{1}{k}-1}\right)+i (c_1-c_2) \sin \left(x \sqrt{\frac{1}{k}-1}\right)$$

$\endgroup$
2
  • $\begingroup$ I meant to solve my ODE and present the solution in a familiar form. I could not see my ODE in your answer. $\endgroup$
    – Akira
    Commented Dec 11, 2023 at 22:09
  • $\begingroup$ The sol is output of your code. $\endgroup$ Commented Dec 11, 2023 at 22:10
3
$\begingroup$

You probably want the Trig solution to your problem

sol = DSolve[-f''[x] + (1 - 1/k) f[x] == 0, f[x], x] // Flatten
(* {f[x] -> C[1] E^((Sqrt[k - 1] x)/Sqrt[k]) + C[2] E^(-((Sqrt[k - 1] x)/Sqrt[k]))} *)

Convert the C's to forms we can manipulate and get the argument of the Sqrt positive based on your range of k

f[x_] = f[x] /. sol /. {C[1] -> c1, C[2] -> c2, Sqrt[k - 1] -> I Sqrt[1 - k]}
(* c1 E^((I Sqrt[1 - k] x)/Sqrt[k]) + c2 E^(-((I Sqrt[1 - k] x)/Sqrt[k])) *)

Convert to trig form

ExpToTrig[f[x]] // Simplify
(* (c1 + c2) Cos[(Sqrt[1 - k] x)/Sqrt[k]] + I (c1 - c2) Sin[(Sqrt[1 - k] x)/Sqrt[k]] *)

And simplify the constants.

f[x_] = % /. {c1 + c2 -> c1, I (c1 - c2) -> c2}
(* c1 Cos[(Sqrt[1 - k] x)/Sqrt[k]] + c2 Sin[(Sqrt[1 - k] x)/Sqrt[k]] *)
$\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.