I am quite new to Mathematica and have an issue regarding which statement.
cut[x_, y_] := which[x>y, doFunctionX[], y>x, doFunctionY[]]
cut/@{X,Y}]
I wish to display only the true case. However, I am unable to find an operation to do it.
I am quite new to Mathematica and have an issue regarding which statement.
cut[x_, y_] := which[x>y, doFunctionX[], y>x, doFunctionY[]]
cut/@{X,Y}]
I wish to display only the true case. However, I am unable to find an operation to do it.
In Mathematica you can do this with function name overloading. Like so:
cut[x_, y_] /; x > y := doFunctionX[]
cut[x_, y_] /; x < y := doFunctionY[]
where the Condition
(/;) operator enforces the conditions you want to place on the arguments.
X
andY
are not numbers (and it should becut[X, Y]
anyway). But, if you changewhich
toWhich
(all built-in functions in Mathematica are capitalized), your code should be fine. When you change that,cut[5, 3]
evaluates todoFunctionX[]
. $\endgroup$ – march Nov 1 at 15:35x == y
. $\endgroup$ – Rohit Namjoshi Nov 1 at 17:54