how to get the coefficients out of the polynomal expression?

天涯浪子 提交于 2019-12-11 15:29:43

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/55183200/how-to-get-the-coefficients-out-of-the-polynomal-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!