@@ -800,9 +800,13 @@ def _common_den(self, imag_tol=None):
800800 num [i ,j ,0 ] = poleset [i ][j ][2 ]
801801 else :
802802 # create the denominator matching this input
803+ # polyfromroots gives coeffs in opposite order from what we use
804+ # coefficients should be padded on right, ending at np
803805 np = len (poles [j ])
804806 den [j ,np ::- 1 ] = polyfromroots (poles [j ]).real
805807 denorder [j ] = np
808+
809+ # now create the numerator, also padded on the right
806810 for i in range (self .outputs ):
807811 # start with the current set of zeros for this output
808812 nwzeros = list (poleset [i ][j ][0 ])
@@ -811,14 +815,15 @@ def _common_den(self, imag_tol=None):
811815 for ip in chain (poleset [i ][j ][3 ],
812816 range (poleset [i ][j ][4 ],np )):
813817 nwzeros .append (poles [j ][ip ])
814-
818+
815819 numpoly = poleset [i ][j ][2 ] * polyfromroots (nwzeros ).real
816- m = npmax - len (numpoly )
817- #print(j,i,m,len(numpoly),len(poles[j]))
818- if m < 0 :
819- num [i ,j ,::- 1 ] = numpoly
820- else :
821- num [i ,j ,:m :- 1 ] = numpoly
820+ # print(numpoly, den[j])
821+ # polyfromroots gives coeffs in opposite order => invert
822+ # numerator polynomial should be padded on left and right
823+ # ending at np to line up with what td04ad expects...
824+ num [i , j , np + 1 - len (numpoly ):np + 1 ] = numpoly [::- 1 ]
825+ # print(num[i, j])
826+
822827 if (abs (den .imag ) > epsnm ).any ():
823828 print ("Warning: The denominator has a nontrivial imaginary part: %f"
824829 % abs (den .imag ).max ())
0 commit comments