How can I parse polynomial expressions to calculate their roots?

1k views Asked by At

First off, I need to implement an JAVA app that will receive an equation (polynomial equation) and my software will calculate its roots. So my objectives:

  • Receive an equation from input (example: x^3 -3x^2 + 2x +1)
  • Parse this equation so I know its coefficients and its degree (coefficients 1, -3, +2, +1, degree: 3, 2, 1, 0)
  • Then I need to find an interval for calculating it roots (like Bolzano method), that find the interval by the signal change in the result of an equation: F(1) = 2, F(2) = -3, that means in the interval of 2 and 3 will be one root) - its required to be one root only per interval.
  • After parsing I'll use Secant Method (or Newton Raphson) for finding the roots.

Those are my goals, If there is anything you can help with, there will be great.

Thanks in advance.

1

There are 1 answers

0
Ira Baxter On

You could build a recursive-descent parser straighforwardly. See https://stackoverflow.com/a/2336769/120163.

However, all you (apparantly) really want to know is the polynomial degree and the coefficients. Why not just read a list of coefficient values, with the list length giving you the polynomial degree?