Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6009 > unrolled thread

FindInstance with all positive numbers

Started byArthur Grabovsky <shukrri@gmail.com>
First post2011-10-29 11:25 +0000
Last post2011-10-30 09:32 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  FindInstance with all positive numbers Arthur Grabovsky <shukrri@gmail.com> - 2011-10-29 11:25 +0000
    Re: FindInstance with all positive numbers "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-30 09:32 +0000

#6009 — FindInstance with all positive numbers

FromArthur Grabovsky <shukrri@gmail.com>
Date2011-10-29 11:25 +0000
SubjectFindInstance with all positive numbers
Message-ID<j8gnrm$5hp$1@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.

[toc] | [next] | [standalone]


#6043

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2011-10-30 09:32 +0000
Message-ID<j8j5k7$f95$1@smc.vnet.net>
In reply to#6009
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@gmail.com> schrieb im Newsbeitrag 
news:j8gnrm$5hp$1@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.
> 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web