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.
XandYare not numbers (and it should becut[X, Y]anyway). But, if you changewhichtoWhich(all built-in functions in Mathematica are capitalized), your code should be fine. When you change that,cut[5, 3]evaluates todoFunctionX[]. – march Nov 01 '19 at 15:35x == y. – Rohit Namjoshi Nov 01 '19 at 17:54