Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: FindInstance with all positive numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122510] Re: FindInstance with all positive numbers
  • From: "Dr. Wolfgang Hintze" <weh at snafu.de>
  • Date: Sun, 30 Oct 2011 04:24:25 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j8gnrm$5hp$1@smc.vnet.net>

Even if this is not very elegant you could use variables a[1], 
...,a[n].
Then you can implment the positivity condition very easily

n = 2;
la = (a[#1] & ) /@ Range[n]
eq = Plus @@ la == 5
cond = And @@ (a[#1] > 0 & ) /@ Range[n]

FindInstance[{eq, cond}, la, Rationals]
FindInstance[{eq, cond}, la, Reals]
FindInstance[{eq, cond}, la, Integers]
Out[94]=
{a[1], a[2]}
Out[95]=
a[1] + a[2] == 5
Out[96]=
a[1] > 0 && a[2] > 0
Out[97]=
{{a[1] -> 5/2, a[2] -> 5/2}}
Out[98]=
{{a[1] -> 5/2, a[2] -> 5/2}}
Out[99]=
{{a[1] -> 4, a[2] -> 1}}

--- Wolfgang



"Arthur Grabovsky" <shukrri at gmail.com> schrieb im Newsbeitrag 
news:j8gnrm$5hp$1 at smc.vnet.net...
> Hi,
>
> To ensure FindInstance[] returns all positive numbers I would do:
>
> FindInstance[a+b=5&&a>0&&b>0,{a,b}];
>
> However I need to do the same but without having to list all 
> individual variables. The reason is that I will be iterating through 
> lists with a large, variable number of elements so writing out 
> a>0&&b>0 all the way until z>0 is impractical.
>
> Thanks.
> 




  • Prev by Date: Defining a Discrete Probability Distribution using ProbabilityDistribution
  • Next by Date: Re: How to combine 2 list
  • Previous by thread: Re: FindInstance with all positive numbers
  • Next by thread: How to combine 2 list