Search code examples
arraysvectorindexingmaple

Change table index to vector index MAPLE


I have a simple problem but I can't seem to figure it out because I am new to Maple.

 for i from 1 to 1 do
 for k from 1 to 4 do
 function_table[i][k] := 2*y[i][k]:
 function_vector[k]  := function_table[i][k]:
 od: od:
 print(function_vector):

output from print is

 table([1 = 2*y[1][1], 2 = 2*y[1][2], 3 = 2*y[1][3], 4 = 2*y[1][4]])

Now what I want to do is take function_vector, and remove the "table index" [1] so I get.

for k from 1 to 4 do
function_vector[k]  := 2*y[k]:
od:
print(function_vector):

table([1 = 2*y[1], 2 = 2*y[2], 3 = 2*y[3], 4 = 2*y[4]])

Basically I have the first expression, and I want to convert it to the second example I gave. For example, is there a command or a short way to make y[1][1] into y[1]?


Solution

  • Here is one way, that works for your given example at least...

    for i from 1 to 1 do
      for k from 1 to 4 do
        function_table[i][k] := 2*y[i][k]:
        function_vector[k]  := function_table[i][k]:
      end do;
    end do:
    print(function_vector):
    
        table([1 = 2 y[1][1], 2 = 2 y[1][2], 3 = 2 y[1][3], 4 = 2 y[1][4]])
    
    
    for x in [indices(function_vector,nolist)] do
      new_vector[x]:=subsindets(function_vector[x],indexed,
                                u->op(0,op(0,u))[op(1,u)]);
    end do:
    print(new_vector);
    
        table([1 = 2 y[1], 2 = 2 y[2], 3 = 2 y[3], 4 = 2 y[4]])