Amber

15 Reputation

2 Badges

11 years, 225 days

MaplePrimes Activity


These are questions asked by Amber

Hi, i'm wondering if theres anything i can do printf and print and have the outputs on the same line. I want the string wihtout any quotations so i think i can only do printf to get this, but then i'm putting an entry out of an array after this. This is a small example out of my code, i would like the output to be all on one line:

The synchronising vector is (S[j-1]) The synchronising word is (X[j-1]) The length of the synchronising word is ...

 

if (sync=true) then 
printf("The Synchronising vector is"); print(S[j-1]);
printf("The sychronising word is");
print(X[j-1]);
printf("The length of the synchronising word is");
print(length(X[j-1]));
else printf("There is no synchronising word"); 
end if;

 At the moment its outputing each print on a new line.

Any help would be much appreciated, thanks.

 

Hi,

I'm currently writing a programme for synchronising automatas, its creates an array and adds words or matrices to the array that aren't already in. I am currently getting an error when i try and run my procedure though and i'm unsure of the problem, any help would be appreciated, here is my code so far.

Thanks!

proc_cerny1:=proc(A::Matrix,B::Matrix,C::Vector[row],N)
local x, S, i, j, T, R, y, found;
x:=2^N;
S:=Array(0..(x-1));
S[0]:=C;
i:=0;
j:=1;
found:=false;

while (i<(x-1) and i<>j) do
T:=S[i].A;
for y from 0 to j do
if LinearAlgebra:-Equal(S[y],T) then
found:=true;
if (found=false) then
S[j]:=T;
j:=j+1;
end if:
end if:
od:

R:=S[i].B;
for y from 0 to j do
if LinearAlgebra:-Equal(S[y],T) then
found:=true;
if (found=false) then
S[j]:=R;
j:=j+1;
i:=i+1;

end if:
end if:
od:
od:
print(S);
end proc:

 

The error i'm getting is when i input this:

proc_cerny1(Matrix([[1,0,0],[1,0,0],[1,0,0]]),Matrix([[0,1,0],[0,0,1],[0,0,1]]),Vector(1..3,1,orientation=row),3);

and the error is:

Error, (in LinearAlgebra:-Equal) invalid input: LinearAlgebra:-Equal expects its 1st argument, X, to be of type {Matrix, Vector} but received 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:

Hi, I am currently creating a procedure so that i can input two matrices and a vector and multiply them together in different patterns, I want the result to be either one of the vectors {4,0,0,0} or {0,4,0,0} or {0,0,4,0} or {0,0,0,4}, I am trying to create an if loop that says is one of the S's is equal to one of these print ("Synchronising"), I have decalred these vectors inside the procedure and all the S's but my if statement is still not working. I think S needs to be decalred more clearly inside but i'm unsure what to do, any help would be much appreciaited! Here is my procedure:

 

proc_cerny1:=proc(A::Matrix,B::Matrix,C::Vector)
local s, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, e, f, g, h;
s:=C.A;
s1:=C.B;
s2:=C.A.B;
s3:=C.B.A;
s4:=C.A.A;
s5:=C.B.B;
s6:=C.A.A.A;
s7:=C.B.B.B;
s8:=C.A.B.B;
s9:=C.A.B.A;
s10:=C.B.B.A;
s11:=C.B.A.A;
s12:=C.A.A.B;
s12:=C.B.A.B;
s13:=C.B.A.A;
s14:=C.B.A.A.A;
e:=Vector([4,0,0,0],orientation=row);
f:=Vector([0,4,0,0],orientation=row);
g:=Vector([0,0,4,0],orientation=row);
h:=Vector([0,0,0,4],orientation=row);
g:=Vector([0,0,4,0],orientation=row);
if (s7 = e)then
print("Synchronising")
elif (s7 = g) then
print ("Synchronising")
elif (s7 = h) then
print ("Synchronising")
elif (s7 = g) then
print("Synchronising")
else
print("Not Synchronising");
end if;

return s, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
end proc:

 

Thanks 

Page 1 of 1