@@ -840,9 +840,13 @@ def _common_den(self, imag_tol=None):
840840 num [i ,j ,0 ] = poleset [i ][j ][2 ]
841841 else :
842842 # create the denominator matching this input
843+ # polyfromroots gives coeffs in opposite order from what we use
844+ # coefficients should be padded on right, ending at np
843845 np = len (poles [j ])
844846 den [j ,np ::- 1 ] = polyfromroots (poles [j ]).real
845847 denorder [j ] = np
848+
849+ # now create the numerator, also padded on the right
846850 for i in range (self .outputs ):
847851 # start with the current set of zeros for this output
848852 nwzeros = list (poleset [i ][j ][0 ])
@@ -851,14 +855,15 @@ def _common_den(self, imag_tol=None):
851855 for ip in chain (poleset [i ][j ][3 ],
852856 range (poleset [i ][j ][4 ],np )):
853857 nwzeros .append (poles [j ][ip ])
854-
858+
855859 numpoly = poleset [i ][j ][2 ] * polyfromroots (nwzeros ).real
856- m = npmax - len (numpoly )
857- #print(j,i,m,len(numpoly),len(poles[j]))
858- if m < 0 :
859- num [i ,j ,::- 1 ] = numpoly
860- else :
861- num [i ,j ,:m :- 1 ] = numpoly
860+ # print(numpoly, den[j])
861+ # polyfromroots gives coeffs in opposite order => invert
862+ # numerator polynomial should be padded on left and right
863+ # ending at np to line up with what td04ad expects...
864+ num [i , j , np + 1 - len (numpoly ):np + 1 ] = numpoly [::- 1 ]
865+ # print(num[i, j])
866+
862867 if (abs (den .imag ) > epsnm ).any ():
863868 print ("Warning: The denominator has a nontrivial imaginary part: %f"
864869 % abs (den .imag ).max ())
0 commit comments