0
$\begingroup$

I would need to solve a third degree equation like $x^3 + a (\theta) x+ b$ where the coefficient of the term of degree 1 depends on some angle $\theta$ (for example, $a(\theta) = \operatorname{cotg}(\theta)$). The question is: how can I write the command so that Mathematica recognizes the coefficient $a(\theta)$ as a functions and separates the various possible cases?

$\endgroup$
3
  • $\begingroup$ Can you please include Mathematica code that you have tried? $\endgroup$
    – Syed
    Commented Apr 15 at 9:26
  • $\begingroup$ The code is Solve[x^3 + Tan[t]*x + 1 == 0, x]. The tangent is just an example $\endgroup$
    – tommy1996q
    Commented Apr 15 at 9:32
  • $\begingroup$ Try: sol = Solve[x^3 + Cot[t]*x + 1 == 0, x]; Plot[Evaluate[x /. sol], {t, 0, 3}] $\endgroup$ Commented Apr 15 at 10:03

3 Answers 3

2
$\begingroup$

For the example you give there is a solution. However, for more general coefficients you may have to go numeric.

sol = Solve[x^3 + Tan[t]*x + 1 == 0, x]

There are three solutions

{{x -> -((2^(1/3) Tan[t])/(-27 + Sqrt[729 + 108 Tan[t]^3])^(
     1/3)) + (-27 + Sqrt[729 + 108 Tan[t]^3])^(1/3)/(
    3 2^(1/3))}, {x -> ((1 + I Sqrt[3]) Tan[t])/(
    2^(2/3) (-27 + Sqrt[729 + 108 Tan[t]^3])^(
     1/3)) - ((1 - I Sqrt[3]) (-27 + Sqrt[729 + 108 Tan[t]^3])^(
     1/3))/(6 2^(1/3))}, {x -> ((1 - I Sqrt[3]) Tan[t])/(
    2^(2/3) (-27 + Sqrt[729 + 108 Tan[t]^3])^(
     1/3)) - ((1 + I Sqrt[3]) (-27 + Sqrt[729 + 108 Tan[t]^3])^(
     1/3))/(6 2^(1/3))}}

The first tends to be real with the other two complex conjugate.

Plotting the first solution gives

Plot[Evaluate[x /. sol[[1]]], {t, -\[Pi], \[Pi]}]

enter image description here

Hope that helps.

$\endgroup$
2
$\begingroup$

If you'd accept a numeric solution, you could use ContourPlot:

ContourPlot[x^3 + Tan[t]*x + 1 == 0, {t, -10, 10}, {x, -10, 10}, FrameLabel -> {"t", "x"}, GridLines -> {Range[-10 π/4, 10 π/4, π], None}]

enter image description here

There seems to be some numerical instability, possibly due to the places where tangent blows up (as indicated by the vertical lines). For this reason, let's rewrite the equation as $\cos(t)\,x^3 + \sin(t)\,x + \cos(t) = 0$ and plot it again:

p1 = ContourPlot[Cos[t] x^3 + Sin[t]*x + Cos[t] == 0, {t, -10, 10}, {x, -10, 10}, FrameLabel -> {"t", "x"}, GridLines -> {Range[-10 π/4, 10 π/4, π], None}]

enter image description here

Then, as long as you eliminate the roots where tangent blows up (only those points that cross the $x$-axis, as far as I can tell here), you can directly extract the points from the plot, using

pts = Cases[Normal@p1, Line[a_] :> a, Infinity];

To see that we've isolated the points:

ListLinePlot@Cases[Normal@p1, Line[a_] :> a, Infinity]

enter image description here

It's periodic, of course, so we can restrict the range of $t$:

ContourPlot[Cos[t] x^3 + Sin[t]*x + Cos[t] == 0, {t, -π/2, π/2}, {x, -10, 10}, FrameLabel -> {"t", "x"}]

enter image description here

$\endgroup$
1
$\begingroup$

Here's a general solution:

sol2 = Block[{q = 1, p = a[t], phi, A},
   A = 2 Sqrt[-p/3];
   phi = ArcCos[(3 q)/(A  p)];
   A*Cos@Table[(phi + 2 Pi  k)/3, {k, 0, 2}]
   ] // TrigExpand

enter image description here

Block[{a = Tan},
 ReImPlot[sol2 // Evaluate, {t, 0, 2 Pi}]
 ]

enter image description here

Block[{a = Tan},
 realneg = Piecewise[{{sol2[[2]], a[t] < 0}}, sol2[[3]]];
 ReImPlot[realneg, {t, -Pi, 2 Pi}]
 ]

enter image description here

$\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.