I need to define a function that behaves as a piecewise function, but will return a string instead of a value. Part of the function that I have written is provided below. The full function continues for several additional lines with additional values of od
and different values for the slot positions. The line of code for od == 1.050
illustrates where I need to return the string "XXS"
. The values od
and tol
are input values to the notebook. The notebook calculates T
.
pipeschedule[od_, tol_, T_] :=
Which[
od == 0.405, Piecewise[{{#1, T <= (tol*#2)}, {#3, (tol*#2) < T <= (tol*#4)}}, "___"]&[40, 0.068, 80, 0.095],
od == 0.540, Piecewise[{{#1, T <= (tol*#2)}, {#3, (tol*#2) < T <= (tol*#4)}}, "___"]&[40, 0.088, 80, 0.119],
od == 0.675, Piecewise[{{#1, T <= (tol*#2)}, {#3, (tol*#2) < T <= (tol*#4)}}, "___"]&[40, 0.091, 80, 0.126],
od == 0.840, Piecewise[{{#1, T <= (tol*#2)}, {#3, (tol*#2) < T <= (tol*#4)}}, "___"]&[40, 0.091, 80, 0.126],
od == 1.050, Piecewise[{{#1, T <= (tol*#2)}, {#3, (tol*#2) < T <= (tol*#4)}, {#5, (tol*#4) < T <= (tol*#6)}, {#7, (tol*#6) < T <= (tol*#8)}}, "___"]&[40,0.109, 80, 0.147, 160, 0.188, "XXS", 0.294]]]
Is there a different function that will accept strings?
If
orSwitch
? $\endgroup$pipeschedule[1.050, 0.1, 0.02]
, I getXXS
as the result from your code. Is that not what you want to get? If you want to avoid usingPiecewise
, it still looks to me likeWhich
should work just fine. $\endgroup$