Efficient computational method for matrix function in dynamic problems