Thank you for the functional programming tip! A month ago, I had no clue about Mathematica. Now I can't stop using it! Here is another problem I encountered (it is about plane waves in physics):
f[x_] := Piecewise[{{E^(I K x) + r E^(-I K x), x <= -a/2}, {t E^(I K x) , x >= a/2}}]
and I want to calculate the wronskian between the function f[a/2] and its conjugate f*[a/2]. I want the same also at x=-a/2. How would I do that with the Piecewise definition? The only way I could do the calculation is by typing it long explicitly (so I could not use the built-in Wronskian[] function):
wronskian=Refine[f[x], Assumptions -> {a > 0, x >= a/2}] D[Refine[Conjugate[f[x]], Assumptions -> {a > 0, x >= a/2}], x] -
Refine[Conjugate@f[x], Assumptions -> {a > 0, x >= a/2}] D[Refine[f[x], Assumptions -> {a > 0, x >= a/2}], x]
All my attempts in defining another function h[x]=Refine[...] do not work because I loose the x dependence of the function (all the parameters become equivalent and the derivative is not performed).
JGuy