At the input I get a polynomial as a string,
I want to get its coefficients in variables, but i have no idea gow do this.
example:7x^4+3x^3-6x^2+x-8
.Maximum degree is not known, coefficients are integers.
I will be very grateful for any help.
Asked
Active
Viewed 63 times
0

Marlock
- 275
- 2
- 9
-
Can any coefficients be negative? – gidds Mar 15 '19 at 13:20
-
is the polynomial expression already simplified (e.g. can you have `x+x`)? How many variables can you have? – user2340612 Mar 15 '19 at 17:30
1 Answers
0
Split by plus and minus (e.g. with re.split), preserving the signs in the results. Then for each substring, split by "x" to get the leading coefficient (+1 and -1 are special cases), and take note of missing powers of x (i.e. coefficient 0).

Inon Peled
- 691
- 4
- 11