Skip to main content
Bounty Ended with 50 reputation awarded by c186282
added 50 characters in body
Source Link
march
  • 24.2k
  • 2
  • 46
  • 102

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 Quantitys 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.

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_]] := 
   fun/output /. Thread[quants[[All, 1]] -> quants] /. 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 Quantitys 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.

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_]] := 
   Expand[fun/output /. Thread[quants[[All, 1]] -> 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 Quantitys 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.

Source Link
march
  • 24.2k
  • 2
  • 46
  • 102

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_]] := 
   fun/output /. Thread[quants[[All, 1]] -> quants] /. 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 Quantitys 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.