Matrix initialization function.