Instead of using UnitConvert
, you can just divide the output by the relevant output unit. Here's one implementation of the idea, based on the OP's version:
ClearAll @ NoUnits;
SetAttributes[NoUnits, HoldAll];
NoUnits[fun_, quants : {__Quantity}, output : Quantity[1, out_]] :=
funExpand[fun/output /. Thread[quants[[All, 1]] -> quants]quants]] /. x_ y_Piecewise :> PiecewiseExpand[x y] /. Quantity[x_, _] :> x
Usage:
LFullNU[l_, T_, a_, b_] = NoUnits2[Lfull[l, T, a, b], {Quantity[l, "Micrometers"], Quantity[T, "Kelvins"]}, Quantity[1, "Microflicks"]];
Seems to work. I have as inputs the full Quantity
s to make the replacements easier.
As a check, you can try
BBNU[l_, T_] = NoUnits2[BB[l, T], {Quantity[l, "Micrometers"], Quantity[T, "Kelvins"]}, Quantity[1, "Microflicks"]];
which yields the same result as in the OP.