use dynamic matrix