I have a probably rather easy-to-solve question. I am solving an equation but receive solutions in terms of complex numbers. However, I am not interested in complex solutions. Moreover, when inserting actual numeric value, the imaginary parts are extremely small, something like 10^(-14)i . This hints on lacking precision and I am happy to ignore these values in the numerical solutions. Yet, I cant wrap my head around the analytical solutions and how I can get rid of the imaginary parts there - how can I impose that all solutions must be real?

I define a triangular function:

triang[x_] := Piecewise[{{0, x <= 0}, 
                         { x / p^2, 0 < x <= p}, 
                         {(2 p - x)/p^2, 2 p > x > p}, 
                         {0, x >= 2 p}}]

Equity := Integrate[y/ae * (x - ss) * triang[x], {x, ss, 2 p}, 
             Assumptions -> ss <= 2 p && p > 0 && ss > 0]

Simplify[Equity, Assumptions -> ae > 0]

--> yields the three different cases, which will be solved individually depending on p and ss --> for simplicity, only the first case follows, as my questions are similar for the others

InvCase1 := (ss y)/ad + ((2 p - ss)^3 y)/(6 ae p^2)

Solve[InvCase1 == inv , ss]

This yields a really lengthy solution including complex parts :/ Any idea how I get only real solutions? All the variables are real and >=0. Thank you!


Roots of cubic equations like this famously require complex expressions when expressed in terms of radicals (look up "Cardano's Formula" with your favorite search engine). If the root is real, the imaginary parts cancel, but may not do so precisely when computing with approximate numbers.

I suggest:

Solve[InvCase1 == inv, ss, Cubics -> False]

This yields a much simpler solution set in terms of Root objects, space age generalizations of bronze age radicals. Root objects representing polynomial roots have the nice property that when evaluated numerically, real roots have no parasitic imaginary parts. For a cubic, one root is guaranteed to be real, and it's the first one (Root[...,1]) of the three.


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.