Message Boards Message Boards

GROUPS:

Calculate and plot the roots of a polynomial?

Posted 10 days ago
99 Views
|
3 Replies
|
0 Total Likes
|

Hi, on mathematica I have represented the following polynomial a * x ^ 4 + b * x ^ 2 + c * x + 2 using the "Plot" command and, through the "Manipulate" command, it is possible to vary the parameters a, b, c. Now, however, I would like the program to give me back the roots of the polynomial according to the parameters a, b, c .... could you help me kindly?

This is the code:

Manipulate[
 Plot[a*x^4 + b*x^2 + c*x + 2, {x, -20, 20}, 
  PlotRange -> {{-20, 20}, {-20, 20}}],
 {a, -1, 1}, {b, -10, 10}, {c, -10, 10}, ControlPlacement -> Right]
3 Replies
Posted 10 days ago

You can use Solve to find the roots. e.g. with a = 1, b = 10, c = 10.

Solve[1*x^4 + 10*x^2 + 10*x + 2 == 0, x]

enter image description here

For a numerical approximation:

NSolve[1*x^4 + 10*x^2 + 10*x + 2 == 0, x]

{{x -> -0.67205}, {x -> -0.277728}, {x -> 0.474889 - 3.23881 I}, {x -> 0.474889 + 3.23881 I}}
Posted 10 days ago

how can I integrate "NSolve" in the "manipulate" command?

Pasquale,

Not sure what you want to do with the roots. Here is one option if you want to show them above the plot.

Manipulate[Module[{poly = a*x^4 + b*x^2 + c*x + 2},
  Pane[roots = NSolve[poly == 0, x];
   Column[
    {
     Style[Column[Prepend[roots, "Roots"]], 10],
     Show[
      Plot[poly, {x, -20, 20}, PlotRange -> {{-20, 20}, {-20, 20}}]]
     }, Alignment -> Center]]],
 {a, -1, 1}, {b, -10, 10}, {c, -10, 10}, ControlPlacement -> Right]

enter image description here

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract