Add slope calculation function