1. Dynamic matrix in Euphoria

Given a series of sets containing a variable number of items (say n 
items), is it possible to have Euphoria define a square matrix 
dynamically, n by n, assigning the nth row and the nth column to the nth 
item of the current set, or would it be necessary to define the matrix 
in advance, hoping that the chosen value of n would be large enough to 
accommodate all possible cases?

Allen

new topic     » topic index » view message » categorize

2. Re: Dynamic matrix in Euphoria

Hi Allen.

You can create empty sequences (seq={}) and use the command append to 
enlarge you matrix to any dimesion.
seq=append(seq,data)

Rubens

At 08:48 20/5/2004, you wrote:
>
>Given a series of sets containing a variable number of items (say n 
>items), is it possible to have Euphoria define a square matrix 
>dynamically, n by n, assigning the nth row and the nth column to the nth 
>item of the current set, or would it be necessary to define the matrix in 
>advance, hoping that the chosen value of n would be large enough to 
>accommodate all possible cases?
>
>Allen
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Dynamic matrix in Euphoria

Allen V Robnett wrote:
> 
> Given a series of sets containing a variable number of items (say n 
> items), is it possible to have Euphoria define a square matrix 
> dynamically, n by n, assigning the nth row and the nth column to the nth 
> item of the current set, or would it be necessary to define the matrix 
> in advance, hoping that the chosen value of n would be large enough to 
> accommodate all possible cases?

That is one of the strong points of Euphoria, you can create sequences 
of as many dimensions as you wish, they are automatically managed. 
How to create them most easily is the only concern.

For example, a square matrix, 4x4, could be created manually:
sequence x
 x = {{0,1,2,3},
      {5,10,15,20},
      {0,0,0,0},
      {0,0,0,0}} 

alternatively, you could create it using: 
constant n = 4
sequence a
   a = repeat(0,n) 
   x = repeat(a,n) 

You can also create variable sizes:
x = {{1,2,3},
     {4,5,6,7,8,9},
     {10},
     {}}

Where ? x[1][3] returns 3
      ? x[3][1] returns 10
      ? x[4] returns {}
      ? x[2][4] returns 7
      and ? x[2] returns {4,5,6,7,8,9}

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

4. Re: Dynamic matrix in Euphoria

irv mullins wrote:

> You can also create variable sizes:
> x = {{1,2,3},
>      {4,5,6,7,8,9},
>      {10},
>      {}}
> 
> Where ? x[1][3] returns 3
>       ? x[3][1] returns 10
>       ? x[4] returns {}
>       ? x[2][4] returns 7
>       and ? x[2] returns {4,5,6,7,8,9}

I probably should have mentioned that these are completely flexible, 
you can add or remove items as needed. Given the above, you could 
do this:

 x[2] = append(x[2],99) (or use the shorthand version: x[2] &= 99)

? x[2] now returns {4,5,6,7,8,9,99}

 x[2] = x[2][1..3]

? x[2] now returns {4,5,6}

Dimensioning and redimensioning of Eu sequences is handled by Eu, not the 
programmer.

Irv

new topic     » goto parent     » topic index » view message » categorize

5. Re: Dynamic matrix in Euphoria

As usual, Euphoria's knights to the rescue.
Many thanks to Rubens and Irv.

Allen

new topic     » goto parent     » topic index » view message » categorize

6. Re: Dynamic matrix in Euphoria

I don't quite get the picture of what allen wants to do,but 
append(seq,data) would expand the # of so called rows .
To keep it square you would then have to do a routine 
to expand all the columns in all the rows.

 seq[i] = append(seq[i],{})
 
Given the unpredictable value of N , we would have to find
the largest value and repeat multiple empty cells first,
then fill in the values.  
 
there's probally a better solution than a square matrix. 
 lets say we want to dynamically accumulate the positions of N;
 seq = {
 {distinct value n} {positions of n}}  
 
 v =  find(n,seq[1])
  if v  then 
 seq[2][v] = append(seq[2][v],position of n) 
-- seq[2][v] += 1 --if we wanted to only count the occurences of n
 else 
 seq[1] = append(seq[1],n)
 seq[2] = append(seq[2],position of n)
 end if 
 

 
   


   

Rubens Monteiro Luciano wrote:
> 
> Hi Allen.
> 
> You can create empty sequences (seq={}) and use the command append to 
> enlarge you matrix to any dimesion.
> seq=append(seq,data)
> 
> Rubens
> 
> At 08:48 20/5/2004, you wrote:
> >
> >Given a series of sets containing a variable number of items (say n 
> >items), is it possible to have Euphoria define a square matrix 
> >dynamically, n by n, assigning the nth row and the nth column to the nth 
> >item of the current set, or would it be necessary to define the matrix in 
> >advance, hoping that the chosen value of n would be large enough to 
> >accommodate all possible cases?
> >

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu