function coeff_range(sys)
%COEFF_RANGE Prints the range of coefficients of dynamic model in state-space representation
    if isa(sys, 'uss')
        sys = ss(sys);
    end
    
    if isa(sys, 'ss')
        if isempty(sys.E)
            coeffs = [sys.A, sys.B; sys.C, sys.D];
        else
            coeffs = [sys.A, sys.B; sys.C, sys.D; sys.E, zeros(size(sys.B))];
        end
    elseif isa(sys, 'tf')
        coeffs = [cell2mat(sys.Numerator(:)') cell2mat(sys.Denominator(:)')];
    elseif isa(sys, 'zpk')
        coeffs = [cell2mat(sys.Z(:)'); cell2mat(sys.P(:)'); sys.K(:)'];
    else
        coeffs = sys;
    end
    
    num_zero = sum(coeffs == 0, 'all');
    coeffs(coeffs == 0) = nan;
    fprintf('Min: %g, Max: %g, Zero: %d, Non-Zero: %d\n', min(abs(coeffs), [], 'all'), max(abs(coeffs), [], 'all'), num_zero, numel(coeffs) - num_zero);

    clf; tiledlayout('flow');
    
    nexttile;
    histogram(log10(abs(coeffs(:))), -50:50);
    text(0.1, 0.67, strsplit(sprintf('Min: %g, Max: %g, Zero: %d, Non-Zero: %d', min(abs(coeffs), [], 'all'), max(abs(coeffs), [], 'all'), num_zero, numel(coeffs) - num_zero), ', '), 'Units', 'normalized');
    title('System Coefficient Magnitude Histogram');
    xlabel('Exponent'); ylabel('Occurances');

    nexttile;
    [X, Y] = meshgrid(1:size(coeffs,1), 1:size(coeffs,2));
    scatter(X(:), Y(:), 50, log10(abs(coeffs(:))), 'filled', MarkerEdgeColor="black");
    %scatter(X(:), Y(:), 50, coeffs(:), "filled", MarkerEdgeColor="black");
    c = colorbar();
    c.Label.String = "Exponent";
    set(gca, YDir="reverse"); xlim([0 size(coeffs,2)+1]); ylim([0 size(coeffs,1)+1]);
    title("System Coefficient Magnitude Heatmap");
    xlabel("Column"); ylabel("Row"); 
end
