Re: combinatory analysis with restrictions [message #41749] |
Wed, 08 December 2004 22:41  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
fleduc@lycos.com (Francois) writes:
> Hello,
>
> Considering 3 variables (a,b,c) that can take 11 discrete values
> between 0 and 1: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9,
> 1.0]
Why don't you make a 2D array of (11,11) corresponding to the sum of
all possible values of A and B?
For each value of (A+B), the value of C is immediately determined as
1-(A+B), or it does not exist if (A+B)>1. Thus, for each entry in the
matrix, you can read off A and B from the column and row labels, and C
from 1-(A+B).
Good luck,
Craig
aa = lindgen(11) # (lonarr(11)+1) ;; A-only matrix
bb = (lonarr(11)+1) # lindgen(11) ;; B-only matrix
cc = 10-(AA+BB)
wh = where(cc GE 0)
a = wh MOD 11 & b = wh/11 & c = cc(wh)
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: combinatory analysis with restrictions [message #41750 is a reply to message #41749] |
Wed, 08 December 2004 21:29   |
Y.T.
Messages: 25 Registered: December 2004
|
Junior Member |
|
|
If I had to do it once, I'd brute-force it:
IDL> for a=0.,1.,.1 do for b=0.,1.,.1 do for c=0.,1.,.1 do $
IDL> if a+b+c eq 1. then print,a,b,c
or some such.
If I had to do this many times, I'd consider pre-filling an array
vaguely like this
IDL> r=intarr(11,11,11)
IDL> for i=0,10 do for j=0,10 do for k=0,10 do $
IDL> if i+j+k eq 10 then r[i,j,k]=1
and then later simply looking up r[a*10,b*10,c*10] ...
cordially
Y.T.
--
Remove YourClothes before you email me.
|
|
|
|
|