Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: function IF with several equality conditions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49111] Re: function IF with several equality conditions
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Thu, 1 Jul 2004 05:26:16 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 6/30/04 at 5:34 AM, mbekkali at gmail.com (Mukhtar Bekkali) wrote:

>I have two questions that HELP file of Mathematica does not
>address:

>(1) How do I implement IF with several conditions.  I tried
>something like this

>a=1; Table[If[{x1>a,x2<a},0,1],{x1,0,2},{x2,0,2}]

>and get no results.

The construct {expr1, expr2 ... } is a list of expressions and doesn't have a true/false value. Change the code to read

Table[If[x1>a && x2<a,0,1],{x1,0,2},{x2,0,2}]

or

Table[If[And@@{x1>a,x2<a},0,1],{x1,0,2},{x2,0,2}]

and you will get what you want

>Also, (2) IF does not accept equality conditions either, say

>a=1; Table[If[x=a,0,1],{x,0,2}]

The operator "=" is the assignment operator not a test for equality. You need to use "==" as in

Table[If[x==a,0,1],{x,0,2}]

>I am surprised that such simple things are not covered by help
>file.

Both of these are covered in the Mathematica Book which is included as part of the Help Browser. But since both the usage of "==" vs "=" and usage of {} to represent lists are fundamental Mathematica syntax, they are not documented again in the documentation for If. 
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Accuracy problem in Mathematica
  • Next by Date: Combining two paramteric plots into one.
  • Previous by thread: Re: function IF with several equality conditions
  • Next by thread: Re: Re: Union - simple question