I have a problem with the DSolve[] command in mathematica 8. Solving the the following 4th order differential equation spits out a complex solution although it should be a real one. The equation is:

y''''[x] + a y[x] == 0

Solving this equation by hand yields a solution with only real parts. All constants and boundary conditions are also real numbers.

The solution I get by hand is:

y1[x_] = (C[5] E^(Power[a, (4)^-1]/Power[2, (2)^-1] x) + 
C[6] E^(-(Power[a, (4)^-1]/Power[2, (2)^-1]) x)) Cos[
Power[a, (4)^-1]/Power[2, (2)^-1]
x] + (C[7] E^(Power[a, (4)^-1]/Power[2, (2)^-1] x) + 
C[8] E^(-(Power[a, (4)^-1]/Power[2, (2)^-1]) x)) Sin[
Power[a, (4)^-1]/Power[2, (2)^-1] x];

Now I have to solve for the constants C[5]...C[8]. This arises a similar issue. I use the Solve[] command with the boundary conditions

Solve[{y1''[-c] == ic0, y1''[c] == ic0 , y1'''[-c] == ic1 , 
y1'''[c] == - ic1 }, {C[5], C[6], C[7], C[8]} ];

The constants C[5]...C[8] are now real if using //Simplify and complex if using //FullSimplify.

Any idea what the reasons are? The notebook with my calculations can be downloaded under: http://dl.dropbox.com/u/4920002/DGL_4th_Order_with_own_solution.nb

In further work I have to use DSolve[] and I would like to understand the issue here.

  • 3
    $\begingroup$ 1. DSolve[] always treats all variables as complex; unless you tell, say, FullSimplify[] that a is real, you'll get the complex bits. 2. You've noticed that the characteristic equation of your DE has complex roots, yes? $\endgroup$ Sep 5, 2012 at 13:37
  • $\begingroup$ Welcome at Mathematica.SE,user2214!. If you don't mind, could you try to focus your creative powers at conceiving a more rememberable username? $\endgroup$ Sep 5, 2012 at 22:16
  • $\begingroup$ Changed my unsername :). Since I am new here I have a question. Is it not appropriate to crosspost in stackexchange and stackoverflow? Are these two webpages the same? $\endgroup$ Sep 6, 2012 at 6:20
  • $\begingroup$ @J.M. : I know that my solution has four Eigenvalues , two sets of complex conjungated Eigenvalues. So I think that I should be able to get a real solution by using real boundary conditions and a real independent variable x $\endgroup$ Sep 6, 2012 at 6:36

3 Answers 3


First, you can't say the solution is a real one, because in the generale case it is not. Take this function:

f[x_] := I*E^(-((a^(1/4) x)/Sqrt[2]))*Sin[(a^(1/4) x)/Sqrt[2]]

It so happens that it is not real (it's pure imaginary), and it is a solution to your differential equation:

enter image description here

Yes, the general form of the solution is thus complex. If you are only interested in real solutions, you have two options:

  1. add some (real) initial conditions, so you get a fully specified real solution after some simplification:

    enter image description here

  2. analyse the general solution to find out how it can be factor into real and complex parts:

    enter image description here

    The first part of that expression is the general equation of the real solutions to your differential equation.

  • $\begingroup$ Hi thanks for your explanations. If I try to Solve the constants C[1]...C[5] for only the real part with my real boundary conditions I get an empty set. my boundary conditions are: y''[-c] == ic0, y''[c] == ic0 , y'''[-c] == ic1 , y'''[c] == - ic1 $\endgroup$ Sep 5, 2012 at 14:31
  • $\begingroup$ Hi again. This morning I tried to solve my equation with the first part of your answer. Unfortunately my computer is still working on it an I do not think it will finish. But the Code I used should be all right. sol1 = DSolve[{y''''[x] + a y[x] == 0, y''[-c] == ic0, y''[c] == ic0 , y'''[-c] == ic1 , y'''[c] == - ic1 }, y[x], x]; Simplify[ComplexExpand[y[x] /. sol1[[1, 1]]], {a > 0, ic0 \[Element] Reals, ic1 \[Element] Reals, c \[Element] Reals}] $\endgroup$ Sep 6, 2012 at 6:28
  • $\begingroup$ I got the first part of your answer running but the function y[x] still has complex values. All boundary conditions are set Reals. Using my boundary conditions yields: sol1 = DSolve[{y''''[x] + a y[x] == 0, y''[-c] == ic0, y''[c] == ic0 , y'''[-c] == ic1 , y'''[c] == - ic1 }, y[x], x]; sol2 = Simplify[ sol1, {a > 0, ic0 -> 1, ic1 -> 2, c -> 3, x \[Element] Reals}]; sol3 = ComplexExpand[y[x] /. sol2[[1, 1]]]; sol4 = Simplify[ sol3, {a > 0, ic0 \[Element] Reals, ic1 \[Element] Reals, c \[Element] Reals, x \[Element] Reals}, TimeConstraint -> 1000] $\endgroup$ Sep 6, 2012 at 8:21

Here is the reply I got from the Mathematica support team:

Thank you for your prompt reply.

Please find attached a small notebook which demonstrates using FullSimplify directly on the output of your first DSolve expression to obtain a symbolic real-valued formula.

The formula itself does contain imaginary values, but these zero each other out as seen when the formula is evaluated numerically. Unfortunately, the corresponding "hidden zero" in the imaginary component cannot be eliminated by either of two typical techniques:

(1) increasing the internal precision available to the N function when evaluating the formula numerically, or

(2) using FullSimplify which is sometimes successful in removing hidden zeros from symbolic formulas.

The recommended approach in cases like this is to use the Chop function, which will eliminate near-zero numerical values in any given expression.

For more information, please see the Possible Issues subsection of the $MaxExtraPrecision page.

For details on the Chop function and how its behavior can be customized, please see its corresponding Documentation Center page.

Please let me know if you have any questions. Thank you.

{sol} = DSolve[{y''''[x] + a y[x] == 0, y''[-c] == ic0, y''[c] == ic0,
 y'''[-c] == ic1, y'''[c] == -ic1}, y[x], x];

val = FullSimplify[sol, a > 0 && {ic0, ic1, c, x} \[Element] Reals]

% // Chop

Block[{$MaxExtraPrecision = 10000}, N[val]]
% // Chop

I think that some of your statements depend on the details. For instance some of the parameters C[] can be complex numbers if you choose a<0 :

parS = Solve[{y1''[-c] == ic0, y1''[c] == ic0, y1'''[-c] == ic1, 
    y1'''[c] == -ic1}, {C[5], C[6], C[7], C[8]}] // Simplify;
parFS = Solve[{y1''[-c] == ic0, y1''[c] == ic0, y1'''[-c] == ic1, 
    y1'''[c] == -ic1}, {C[5], C[6], C[7], C[8]}] // FullSimplify

parS /. {a -> -2, c -> 10, ic0 -> 1, ic1 -> -1} // N
parFS /. {a -> -2, c -> 10, ic0 -> 1, ic1 -> -1} // N

(* {{C[5] -> -0.35876 - 2.498*10^-15 I,  C[6] -> -0.35876 - 2.498*10^-15 I, 
     C[7] -> 2.27596*10^-15 - 0.358762 I, C[8] -> -2.27596*10^-15 + 0.358762 I}}

   {{C[5] -> -0.35876 + 5.10703*10^-15 I, C[6] -> -0.35876 + 5.10703*10^-15 I, 
     C[7] -> 2.35922*10^-15 - 0.358762 I, C[8] -> -2.19269*10^-15 + 0.358762 I}} *)

Besides this point you can get the solution to your problem in one line and indeed it seems a real function (apart from numerics) :

sol[a_, ic0_, ic1_, c_, x_] = y[x] /. DSolve[{y''''[x] + a y[x] == 0, y''[-c] == ic0, 
     y''[c] == ic0, y'''[-c] == ic1, y'''[c] == -ic1}, y[x], x][[1]] ;

Plot[Im[sol[-2.0, 1.0, -1.0, 10., x]], {x, -10., 10.}]
Plot[Re[sol[-2.0, 1.0, -1.0, 10., x]], {x, -10., 10.}]

Im Re

  • $\begingroup$ Hi,Thanks for your answer. I forgot to give the download link for my notebook. it can be downloaded under: dl.dropbox.com/u/4920002/DGL_4th_Order_with_own_solution.nb I also get this behaviour in the symbolic calculation (in the notebook y3[x] is Real and y4[x] is complex). Also for a>0 I get complex constants $\endgroup$
    – user1622055
    Sep 4, 2012 at 10:13

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.