For these pieces of code how can I “r” evaluated.
When I use If “r” remains unevaluated.
When I use Which “r” is on ly evaluated when the first case is True.
Can I get some help? Thanks
I would define fIf and fWhich this way, with explicit w variable:
fIf[u_, v_, w_] := Module[{aa = u + v + w, bb = 2 u - v - w},
r = Which[bb > aa, BB, aa > bb, AA, aa == bb, AB];
{aa, bb, r}]
fWhich[u_, v_, w_] := Module[{aa = u + v + w, bb = 2 u - v - w},
r1 = Which[aa == bb, AB, aa > bb, AA, bb > aa, BB];
r2 = Which[aa > bb, AA, aa == bb, AB, bb > aa, BB];
r3 = Which[bb > aa, BB, aa > bb, AA, aa == bb, AB];
{aa, bb, r1, r2, r3}]
thanks. Yes it works for this tailor-made example,
But the issue is this one in fact
Clear[aa,bb,r1,r2,r3];
aa= u+v+w;bb= 2 u-v-w;
r4[u_,v_]=Which[aa>bb,AA,aa==bb,AB,aa>bb,AA,bb>aa,BB];
r4[2,1] yields to
Which[3 + w > 3 - w, AA, aa == bb, AB, aa > bb, AA, bb > aa, BB]
where only the first occurence of aa and bb are replaced by their value in u,v,w and then evaluated