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


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

Consecutive variables from matrix

Started byJesse Pisel <jessepisel@gmail.com>
First post2013-01-08 04:04 +0000
Last post2013-01-08 16:43 +0000
Articles 2 — 2 participants

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


Contents

  Consecutive variables from matrix Jesse Pisel <jessepisel@gmail.com> - 2013-01-08 04:04 +0000
    Re: Consecutive variables from matrix Ray Koopman <koopman@sfu.ca> - 2013-01-08 16:43 +0000

#13054 — Consecutive variables from matrix

FromJesse Pisel <jessepisel@gmail.com>
Date2013-01-08 04:04 +0000
SubjectConsecutive variables from matrix
Message-ID<kcg5t1$rcn$1@smc.vnet.net>
I don't know if I am going about this problem the wrong way or if it is even possible to use this method. I am interested in assigning the different rows of a 4x4 matrix to variables d1-d4 and the first value of a different matrix to a variable t and using the variables in an if then statement. An example of what I am trying to do is:

data1 = RandomReal[{0, 10}, {4, 4}]
data2 = RandomReal[{0, 10}, {4, 4}]
t = data2[[1, 1]]
d1 = data1[[1, 1]]
d2 = data1[[1, 2]]
d3 = data1[[1, 3]]
d4 = data1[[1, 4]]
If[t < d1 \[And] t < d2 \[And] t < d3 \[And] t < d4, 0, 1]

But what I want to do is run through the first row of values in the data2 with the first row of values from data1 without having to write out all the different possible combinations eg:

data1 = RandomReal[{0, 10}, {4, 4}]
data2 = RandomReal[{0, 10}, {4, 4}]
t = data2[[1, 1]]
d1 = data1[[1, 1]]
d2 = data1[[1, 2]]
d3 = data1[[1, 3]]
d4 = data1[[1, 4]]
If[t < d1 \[And] t < d2 \[And] t < d3 \[And] t < d4, 0, 1]

data1 = RandomReal[{0, 10}, {4, 4}]
data2 = RandomReal[{0, 10}, {4, 4}]
t = data2[[1, 2]]
d1 = data1[[1, 1]]
d2 = data1[[1, 2]]
d3 = data1[[1, 3]]
d4 = data1[[1, 4]]
If[t < d1 \[And] t < d2 \[And] t < d3 \[And] t < d4, 0, 1]

and so on for all the different combinations without having to use brute force. So in review I would like to be able to assign variables d1,d2,d3,d4 to the values in the first row, compare to variable t assigned to the first then second then third and fourth entries of the other matrix and then move to the next row in both matrices. Essentially reassigning the variables d1,d2,d3,d4 and t as the notebook runs.

Any ideas on how to accomplish this and have the output in matrix/list form would be much appreciated.

Thanks 

[toc] | [next] | [standalone]


#13064

FromRay Koopman <koopman@sfu.ca>
Date2013-01-08 16:43 +0000
Message-ID<kchib3$11f$1@smc.vnet.net>
In reply to#13054
On Jan 7, 8:04 pm, Jesse Pisel <jessepi...@gmail.com> wrote:
> I don't know if I am going about this problem the wrong way or if it is even possible to use this method. I am interested in assigning the different rows of a 4x4 matrix to variables d1-d4 and the first value of a different matrix to a variable t and using the variables in an if then statement. An example of what I am trying to do is:
>
> data1 = RandomReal[{0, 10}, {4, 4}]
> data2 = RandomReal[{0, 10}, {4, 4}]
> t = data2[[1, 1]]
> d1 = data1[[1, 1]]
> d2 = data1[[1, 2]]
> d3 = data1[[1, 3]]
> d4 = data1[[1, 4]]
> If[t < d1 \[And] t < d2 \[And] t < d3 \[And] t < d4, 0, 1]
>
> But what I want to do is run through the first row of values in the data2 with the first row of values from data1 without having to write out all the different possible combinations eg:
>
> data1 = RandomReal[{0, 10}, {4, 4}]
> data2 = RandomReal[{0, 10}, {4, 4}]
> t = data2[[1, 1]]
> d1 = data1[[1, 1]]
> d2 = data1[[1, 2]]
> d3 = data1[[1, 3]]
> d4 = data1[[1, 4]]
> If[t < d1 \[And] t < d2 \[And] t < d3 \[And] t < d4, 0, 1]
>
> data1 = RandomReal[{0, 10}, {4, 4}]
> data2 = RandomReal[{0, 10}, {4, 4}]
> t = data2[[1, 2]]
> d1 = data1[[1, 1]]
> d2 = data1[[1, 2]]
> d3 = data1[[1, 3]]
> d4 = data1[[1, 4]]
> If[t < d1 \[And] t < d2 \[And] t < d3 \[And] t < d4, 0, 1]
>
> and so on for all the different combinations without having to use brute force. So in review I would like to be able to assign variables d1,d2,d3,d4 to the values in the first row, compare to variable t assigned to the first then second then third and fourth entries of the other matrix and then move to the next row in both matrices. Essentially reassigning the variables d1,d2,d3,d4 and t as the notebook runs.
>
> Any ideas on how to accomplish this and have the output in matrix/list form would be much appreciated.
>
> Thanks

If you want to change data1 and/or data2 between checks,
which is what your sample code does, then

  UnitStep[ data2[[1,j]] - Min@data1[[1]] ]

will give 0 or 1 according as the j'th term in row 1 of data2
is or is not less than all the terms in row 1 of data1.

If you want to use the same data1 and data2 throughout then
this will give a vector in which each term will be 0 or 1
according as the corresponding term in row 1 of data2
is or is not less than all the terms in row 1 of data1.

  UnitStep[ data2[[1]] - Min@data1[[1]] ]

[toc] | [prev] | [standalone]


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


csiph-web