Evaluating A Piecewise Integral with the Step Function I am trying to find the expectation value of the Hamiltonian for the piecewise function: $$ \begin{cases} \ Ax & 0\leq x\leq a/2 \\
      A(a-x) & a/2\leq a 
   \end{cases}
$$
Using a stepwise function. I take the first derivative and write it using the step function, then I get the second derivative to be $$-2A\delta(x-\frac{a}{2})$$ But first of all I was wondering if it is always ok to take the first derivative and then write that using a step function because I get different answers if I write the function itself with a step function and differentiate from there. My second question is whether I now still have to do a piecewise integration using my step function since my function is still piecewise. I tried doing a piecewise integration using my second derivative in this form but I get the answer wrong by a factor of 2. So I am not sure how to integrate to find the expectation value of my Hamiltonian after I get my step function.
 A: Formally you want to first write your wave function using step functions, then take the derivative(s) and so on. 
In your particular case you get lucky because the delta terms that arise in the derivative cancel each other out and then you can calculate the matrix element using just derivatives expressed in terms of step functions. 
In other words, you don't loose much if you simply write the derivatives with step functions from the get go, but you are not quite rigorous either.
So, if you take
$$
\Psi(x) = \Theta\left(\frac{a}{2} - x\right)A x + \Theta\left(x - \frac{a}{2}\right)A(a-x)
$$
the derivative reads
$$
\frac{d\Psi}{dx} = \frac{d\Theta\left(\frac{a}{2} - x\right)}{dx} Ax + A\Theta\left(\frac{a}{2} - x\right) + \frac{d\Theta\left(x - \frac{a}{2}\right)}{dx} A(a -x) - A\Theta\left(x - \frac{a}{2}\right) = \\
= - \delta\left(\frac{a}{2} - x \right)Ax + A\Theta\left(\frac{a}{2} - x\right) + \delta\left(x-\frac{a}{2}\right) A(a-x) - A\Theta\left(x - \frac{a}{2}\right) = \\
= - 2A\left(\frac{a}{2} - x \right)\delta\left(\frac{a}{2} - x \right) + A\Theta\left(\frac{a}{2} - x\right) - A\Theta\left(x - \frac{a}{2}\right) = \\
= A\Theta\left(\frac{a}{2} - x\right) - A\Theta\left(x - \frac{a}{2}\right) 
$$
where the 3rd line follows from $\delta\left(\frac{a}{2} - x \right) = \delta\left(x-\frac{a}{2}\right)$ and the last line from $\delta\left(\frac{a}{2} - x \right)\left(\frac{a}{2} - x \right) = 0$ (a version of $x\delta(x) = 0$).
As for the Hamiltonian matrix element, you don't need to take the 2nd derivative any more since 
$$
- \int_0^a{dx\; \Psi^*(x) \frac{d^2\Psi}{dx^2}} = \int_0^a{dx\; \frac{d\Psi^*}{dx} \frac{d\Psi}{dx}}
$$
after integration by parts.
