add matrix version for almost of all functions