Re: Domains
- To: mathgroup at smc.vnet.net
- Subject: [mg85330] Re: Domains
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Wed, 6 Feb 2008 05:40:43 -0500 (EST)
- References: <foavks$hn3$1@smc.vnet.net>
Akki wrote:
> Hi,
>
> How does one create a domain for a variable in Mathematica ?
>
> For e.g. x is a variable and I would like to create a domain for x
> consisting of 3, 5, 7 only.
> i.e. dom = {3,5,7} then use the condition \Element[x,dom]
>
> Thanks,
> Akki
>
Variables don't have domains as such, but you can create a variable that
contains a list that will act as a domain. Thus, suppose you have:
xdom={3,5,7};
then you can test if x is in that domain by using:
MemberQ[xdom,x]
It might be helpful if you described at slightly greater length what it
is you are trying to do - maybe with some code. For example, as written,
it is up to you to remember that xdom is the domain of x. If you were
dealing with many variables, it might be worth automating this so that
you could write something like withinDomain[x].
David Bailey
http://www.dbaileyconsultancy.co.uk