add generate matrix and calc negative elements