Moved matrix_from_function to QM_helpers.