Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.4K Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Evaluation inside If or Which function

Posted 10 years ago

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

Attachments:
POSTED BY: Alain RIWAN
2 Replies
Posted 10 years ago
POSTED BY: Alain RIWAN

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}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard