On 4/9/07, Miquel Poch <[EMAIL PROTECTED]> wrote:

Hi,

I've got a function write in Matlab, and I need to tranlate it into
python. I've found an expresion like this:
?
BF = b0 + (b1 + (b2 + (b3 + (b4 + (b5 + b6*T).*T).*T).*T).*T).*T
or
dBFdT = b1 + (2 * b2 + (3 * b3 + (4 * b4 + (5 * b5 + 6*
b6*T).*T).*T).*T).*T


It's Horner's method for evaluating polynomials and their derivatives. You
can also do this in numpy as:

In [5]: p1,p2,p3,p4,p5,p6 = [1,2,3,4,5,6]

In [6]: p = poly1d([p6,p5,p4,p3,p2,p1])

In [7]: T = array([[1,2],[3,4]])

In [8]: p(T)
Out[8]:
array([[  21,  321],
      [2005, 7737]])

In [9]: polyder(p)(T)
Out[9]:
array([[  70,  702],
      [3098, 9178]])

Note the reversal of the coefficient order. Just make sure your arrays are
floats, the example I gave is all integers.

Chuck
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to