Let the following equation have two equal roots:
f[x_] := x^3 - p x^2 + q x - r
And I want to find out what the three roots are. Not knowing how to put this condition within a Solve or Reduce, I have to rely on transcribing some algebra into MMA.So if the above equation has two equal roots, then
fr[x_] := 3 x^2 - 2 p x + q
has one of them, out of a theorem on the depression of equations.If I put this into Solve this leads to:
Solve[x^3 - p x^2 + q x - r == 0 && 3 x^2 - 2 p x + q == 0, x]
No error message but MMA is unable to give here one the the duplicate solution.So I put more algebra into the code:
PolynomialRemainder[f[x], fr[x], x] (* the remainder must he equal to zero *)rootduplicate = x /. Solve[% == 0, x] (* gives the value of the two equal roots *)
The third root is within the third factor of f[x]:
PolynomialQuotient[f[x], (x - rootduplicate[[1]])^2, x] // FullSimplifySolve[% == 0, x]root3 = x /. {%}
Let's check it up with an example:
Solve[(x^3 - p x^2 + q x - r /. {p -> 4, q -> 5, r -> 2}) == 0 && (3 x^2 - 2 p x + q /. {p -> 4, q -> 5}) == 0, x] (* now MMA finds a double root *)Solve[(x^3 - p x^2 + q x - r /. {p -> 4, q -> 5, r -> 2}) == 0 , x] rootduplicate /. {p -> 4, q -> 5, r -> 2}root3 /. {p -> 4, q -> 5, r -> 2}root3 == {(p - 2 rootduplicate)} // FullSimplify (* another verification out of algebra - is there a way with MMA to find out this relation without hardcoding it? *)
My questions:
- Why MMA (V8) is unable to find a solution in my first Solve ?
- Is there a better way relying less on algebra to get these solutions?