@@ -904,14 +904,25 @@ def minreal(self, tol=None):
904904 num = _create_poly_array ((self .noutputs , self .ninputs ))
905905 den = _create_poly_array ((self .noutputs , self .ninputs ))
906906
907+ # Remove small coefficients
908+ num_array , den_array = self .num_array .copy (), self .den_array .copy ()
909+ max_coeff = 0
910+ for i , j in product (range (self .noutputs ), range (self .ninputs )):
911+ max_coeff = max (max_coeff , np .max (np .abs (num_array [i , j ])).item ())
912+ max_coeff = max (max_coeff , np .max (np .abs (den_array [i , j ])).item ())
913+ threshold = tol or float_info .epsilon * max_coeff
914+ for i , j in product (range (self .noutputs ), range (self .ninputs )):
915+ num_array [i , j ][np .abs (num_array [i , j ]) < threshold ] = 0
916+ den_array [i , j ][np .abs (den_array [i , j ]) < threshold ] = 0
917+
907918 for i in range (self .noutputs ):
908919 for j in range (self .ninputs ):
909920
910921 # split up in zeros, poles and gain
911922 newzeros = []
912- zeros = roots (self . num_array [i , j ])
913- poles = roots (self . den_array [i , j ])
914- gain = self . num_array [i , j ][0 ] / self . den_array [i , j ][0 ]
923+ zeros = roots (num_array [i , j ])
924+ poles = roots (den_array [i , j ])
925+ gain = num_array [i , j ][0 ] / den_array [i , j ][0 ]
915926
916927 # check all zeros
917928 for z in zeros :
0 commit comments