Question: How do i write an if loop to say if this is already in the array then do not add it to the array?

December 09 2013 Amber 10

0

Hi, I am trying to write a procedure that inputs two matrices (A,B) and vector (C), it then multiplies C by A, and thenC by B and adds these to the array, it then multiplies each other them by A and B and adds them to the array etc up to (N-1)^2 (N will be given), this is what I hve so far, I am trying to write an if loop inside to say if it's already in the array then do not add it again but i'm unsure. Any help would be appreciated thanks!

 

proc_cerny1:=proc(A::Matrix,B::Matrix,C::Vector,N)
local x, S, i, j, T, R, y;
x:=(N-1)^2;
S:=Array([]);
S[0]:=C;
i:=0;
j:=0;
while (i<(2^N)) do
T=S[i].A;
S[j]=T;
j=j+1;
R=S[i].B;
S[j]=R;
i=i+1;
for y from 0 to j do
if (S[y]=T) then
S[i]=S[i]-T;
fi:
od:
print(S);
end proc:

Please Wait...