Evaluating Polynomial coefficients

后端 未结 5 1868
甜味超标
甜味超标 2020-12-18 13:07

I\'m trying to write a function that takes as input a list of coefficients (a0, a1, a2, a3.....a n) of a polynomial p(x) and the value x. The function will return p(x), whic

5条回答
  •  無奈伤痛
    2020-12-18 13:33

    Either with recursion, or without, the essence of the solution is to create a loop on "n", because the polynomial starts at x^0 and goes up to a_n.x^n and that's the variable you should also consider as an input. Besides that, use a trick called multiply and accumulate to be able to calculate partial results on each loop iteration.

提交回复
热议问题