Change algorithm matrix filling