Kid Charlamagne
Kid Charlamagne

Reputation: 588

create polymial in powers of (x-1) from given coefficients in python

I have the following coefficient matrix.

import numpy as np
coeffMatrix = np.array([[  1.        ,   1.46599761,   0.        ,   0.25228421],
   [  2.71828183,   2.22285026,   0.75685264,   1.69107137],
   [  7.3890561 ,   8.80976965,   5.83006675,  -1.94335558],
   [ 20.08553692,   0.        ,   0.        ,   0.        ]])

I can then create a polynomials s0 as follows:

s0 = np.poly1d(coeffMatrix[0][::-1])
print (s0)

It prints out the following output:

        3
0.2523 x + 1.466 x + 1

I now want to create s1 using coeffMatrix[1][::-1] as the coefficients but I want s1 to be in powers of (x-1).

How can I do this?

On a side note. I don't know how to copy paste jupyter notebook input output straight into stackoverflow.

Upvotes: 1

Views: 99

Answers (1)

Ophir Carmi
Ophir Carmi

Reputation: 2921

Use variable parameter. I used http://docs.scipy.org/doc/numpy/reference/generated/numpy.poly1d.html

(I prefer to look on np.array as matrix and not as list of arrays)

s1 = np.poly1d(coeffMatrix[1, ::-1], variable='(x-1)')
print(s1)

Upvotes: 1

Related Questions