Calculates the scalar multiplication of a function.