Message Boards Message Boards

0
|
231 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to fill in an empty list {} using for loop twice?

Posted 5 days ago

Hello, this is my first question ever in this forum.
I have a program to execute that gives the subgroups maximal chains that starts from a certain subgroup(which is in this case is <alpha, beta> , See the code to understand).
I'm posting here just a part of the long program, but any way, let me explain the issues I have. It started to how to fill a list, I looked up in the internet for some answers, some suggest using ApendTo, but I don't like it; at the start the desired list is empty {})(look up for l3 in the code), secondly after running I get a message that part 3 of {alpha, beta} dosen't exist which is absolutely true, but I don't understand why; theoretically inside the double loop For j.......For i....... there is no call for a third part of l1={alpha, beta} since i starts from 1 up to Length[l1]=2.
However, even the program returns errors (at least!!!!!) but it seems that it skips the step j=1, and giving incomplete results.
If anyone could point me where I made the mistake(or mistakes!) I would be more than grateful.

Funcion[L_, c_, k_, p_] := Module[{a1, a2, a3, a4, j},
  a1 = L;
  a2 = Length[L];
  a3 = L; j = k;
  While[j < k + p,
   a4 = Length[a3] - (a2 - j);
   a3 = ReplacePart[a3, a4 -> Row[c, ","]];
   j++];
  a3]
(*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*)
\[Alpha] = {0, 0, 4};
\[Beta] = {0, 2, 0};
\[Gamma] = {1, 0, 0};
a = {0, 0, 2};
b = {0, 1, 0};
A = {\[Alpha], \[Beta], \[Gamma]};
B = {a, b, a + b, a + \[Gamma], b + \[Gamma], a + b + \[Gamma]};
f[x_, y_] := 
 Which[x[[1]] - y[[1]] >= 0 && x[[2]] - y[[2]] >= 0 && 
   x[[3]] - y[[3]] >= 0, 1, 
  x[[1]] - y[[1]] < 0 || x[[2]] - y[[2]] < 0 || x[[3]] - y[[3]] < 0, 
  0]
g[x_, y_] := 
 Which[2*x[[1]] - y[[1]] >= 0 && 2*x[[2]] - y[[2]] >= 0 && 
   2*x[[3]] - y[[3]] >= 0, 1, 
  2*x[[1]] - y[[1]] < 0 || 2*x[[2]] - y[[2]] < 0 || 
   2*x[[3]] - y[[3]] < 0, 0]
  (*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*)
CadenasMaximas[L_] := 
 Module[{l1, l2, l3, l4, l5, l6, l7, l8, l9, h, constant1, constant2, 
   constant3, Cadenas1, Cadenas2, Cadenas3},
  l1 = L; l2 = {}; l3 = {}; l4 = {};  l5 = {};  l6 = {}; l7 = {};  
  l8 = {}; l9 = {}; h = 0; Cadenas1 = {};
  Cadenas2 = {}; Cadenas3 = {}
  (* l2= c2*c2*c2,    l3=c2*c4,     l4=c2*c2*c4,    l5=c4*c4, l6=c2*
  c8,     l7=c2*c4*c4,    l8=c2*c2*c8, l9=c4*c8 *);
  constant2 = {0, 0}; constant3 = {0, 0};
  Label[uno];
   For[j = 1, j <= Length[A], j++, For[i = 1, i <= Length[l1], i++,
              If [f[l1[[i]], A[[j]]] == 1, h = h + 1, h = h + 0];
                                                                      \
         ];
   If [h < 1, l2 = Append[l1, A[[j]]]];
   h = 0;
          ];
  If[Length[l2] == 3, Goto[dos], Goto[uno]];
  Label[dos];
  For[j = 1, j <= Length[B], j++, For[i = 1, i <= Length[l1], i++;
     If [g[B[[j]], l1[[i]]] == 1, h = h + 1, h = h + 0];
                                                             ];
    If [h > 0, l3 = Append[l3, Append[l1, B[[j]]]]];
      ];
  Print[l3]
]
  (*""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""\
""""""""""""""""""""""""""""""""""""""""*)

  S = {\[Alpha], \[Beta]};
CadenasMaximas[S](*And this is what I get after running it: a lot of errors then this
 {{{0,0,4},{0,2,0},{0,1,0}},{{0,0,4},{0,2,0},{0,1,2}},{{0,0,4},{0,2,0},{1,0,2}},{{0,0,4},{0,2,0},{1,1,0}},{{0,0,4},{0,2,0},{1,1,2}}},
 which is {{\[Alpha], \[Beta],b},{\[Alpha], \[Beta],a+b},{\[Alpha], \[Beta],a+\[Gamma]},{\[Alpha], \[Beta],b+\[Gamma]},{\[Alpha], \[Beta],a+b+\[Gamma]}}*)
POSTED BY: Issam EL MARIAMI
3 Replies

it will be used in the rest of the algorithm which I didn't provide

POSTED BY: Issam EL MARIAMI
Posted 5 days ago

After Label[dos], the inner For loop has this:

For[i = 1, i <= Length[l1], i++; ...other stuff...]

Notice that you used a ; when you should have used a ,.

POSTED BY: Eric Rimbey
Posted 5 days ago

Why did you provide Funcion when it's never used?

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract