The function 'gram' in the Control System Toolbox only computes the controllability gramian for stable systems. This program calculates the controllability gramian for an unstable system (A,B) as long as the matrix A has no imaginary axis poles.
It is based on the paper by Zhou et al. (1999), 'Balance realization and model reduction for unstable systems', International Journal of Robust and Nonlinear Control, vol. 9, 182-198.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.