Now same output as matlab code