generalize matrix