Jabz

433 Reputation

5 Badges

15 years, 243 days

MaplePrimes Activity


These are replies submitted by Jabz

It seems to be working now thanks but is my code correct. Meaning the second part when the matrix is fliped (transformed) is the procedure working. I tried to trace the proc to see if it is goi ng through all the loops but it didnt work.

with(MTM):with(ArrayTools):
Diagn:=proc(n)
local m,en,j,t,m1,k,s,q,w:
m:=n:
en:=min(op(1,m))-1:
for j from -(en) to en do
q:=diag(m,j);
t:=AddAlongDimension(q,1);
if t > 1  then
return(No)
fi:
od;
m1:=FlipDimension(m,2);
for k from -(en) to en do
w:=diag(m1,k);
s:=AddAlongDimension(w,1);
if s > 1 then
return(No1)
fi:
od;
return(yes)
end proc:
 

It seems to be working now thanks but is my code correct. Meaning the second part when the matrix is fliped (transformed) is the procedure working. I tried to trace the proc to see if it is goi ng through all the loops but it didnt work.

with(MTM):with(ArrayTools):
Diagn:=proc(n)
local m,en,j,t,m1,k,s,q,w:
m:=n:
en:=min(op(1,m))-1:
for j from -(en) to en do
q:=diag(m,j);
t:=AddAlongDimension(q,1);
if t > 1  then
return(No)
fi:
od;
m1:=FlipDimension(m,2);
for k from -(en) to en do
w:=diag(m1,k);
s:=AddAlongDimension(w,1);
if s > 1 then
return(No1)
fi:
od;
return(yes)
end proc:
 

Thank u. Can you please tell me what's wrong with the code i coded below. It was supposed to add along the diagonals and if any of the diagonals sum is greater than 1 then it should return ' No ' but it keeps on returning ' yes '???
 

with(MTM):with(ArrayTools):
Diagn:=proc(n)
local m, en, j , t , m1, k , s :
m : = n :

en:=min(op(1,m))-1:
for j from -(en) to en do
diag(m,j);
t:=AddAlongDimension(%,1);
if t > 1 then
return(No)
else return(yes)
fi:
od;
m1:=FlipDimension(m,2);
for k from -(en) to en do
diag(m1,k);
s:=AddAlongDimension(%,1);
if s > 1 then
return(No1)
else return(yes1)
fi:
od;
end proc:
n:=Matrix([[1,0,0,0],[0,0,1,0],[0,0,0,1],[0,1,0,0];
Diagn(n);
                                                                yes

Thank u. Can you please tell me what's wrong with the code i coded below. It was supposed to add along the diagonals and if any of the diagonals sum is greater than 1 then it should return ' No ' but it keeps on returning ' yes '???
 

with(MTM):with(ArrayTools):
Diagn:=proc(n)
local m, en, j , t , m1, k , s :
m : = n :

en:=min(op(1,m))-1:
for j from -(en) to en do
diag(m,j);
t:=AddAlongDimension(%,1);
if t > 1 then
return(No)
else return(yes)
fi:
od;
m1:=FlipDimension(m,2);
for k from -(en) to en do
diag(m1,k);
s:=AddAlongDimension(%,1);
if s > 1 then
return(No1)
else return(yes1)
fi:
od;
end proc:
n:=Matrix([[1,0,0,0],[0,0,1,0],[0,0,0,1],[0,1,0,0];
Diagn(n);
                                                                yes

Thank u. Can you please tell me what's wrong with the code i coded below. It was supposed to add along the diagonals and if any of the diagonals sum is greater than 1 then it should return ' No ' but it keeps on returning ' yes '???
 

with(MTM):with(ArrayTools):
Diagn:=proc(n)
local m, en, j , t , m1, k , s :
m : = n :

en:=min(op(1,m))-1:
for j from -(en) to en do
diag(m,j);
t:=AddAlongDimension(%,1);
if t > 1 then
return(No)
else return(yes)
fi:
od;
m1:=FlipDimension(m,2);
for k from -(en) to en do
diag(m1,k);
s:=AddAlongDimension(%,1);
if s > 1 then
return(No1)
else return(yes1)
fi:
od;
end proc:
n:=m;
Diagn(n);
 

Thank u. Can you please tell me what's wrong with the code i coded below. It was supposed to add along the diagonals and if any of the diagonals sum is greater than 1 then it should return ' No ' but it keeps on returning ' yes '???
 

with(MTM):with(ArrayTools):
Diagn:=proc(n)
local m, en, j , t , m1, k , s :
m : = n :

en:=min(op(1,m))-1:
for j from -(en) to en do
diag(m,j);
t:=AddAlongDimension(%,1);
if t > 1 then
return(No)
else return(yes)
fi:
od;
m1:=FlipDimension(m,2);
for k from -(en) to en do
diag(m1,k);
s:=AddAlongDimension(%,1);
if s > 1 then
return(No1)
else return(yes1)
fi:
od;
end proc:
n:=m;
Diagn(n);
 

My procedure still does not work and i cant seem to work out why? For the following matrix it should return ' yes ' but it returns '  no '.
 

m:=Matrix([[0,0,1,0],[1,0,0,0],[0,0,0,1],[0,1,0,0]]):

 

n:=m:

with(ArrayTools):
RownColumn:=proc(n)
local m, en, q, w,r,s, Arr:
m:=n:
en:=min(op(1,m)):
Arr:=Array(1..en,fill = 1):
q:=AddAlongDimension(m,1):

w:=AddAlongDimension(m,2):

r:=convert(q,Array):
s:=convert(w,Array):
if r = Arr and s = Arr then

return(yes)  
else
return(No)
fi:
end proc:
n:=m;
RownColumn(n);

                                                                       No
 

My procedure still does not work and i cant seem to work out why? For the following matrix it should return ' yes ' but it returns '  no '.
 

m:=Matrix([[0,0,1,0],[1,0,0,0],[0,0,0,1],[0,1,0,0]]):

 

n:=m:

with(ArrayTools):
RownColumn:=proc(n)
local m, en, q, w,r,s, Arr:
m:=n:
en:=min(op(1,m)):
Arr:=Array(1..en,fill = 1):
q:=AddAlongDimension(m,1):

w:=AddAlongDimension(m,2):

r:=convert(q,Array):
s:=convert(w,Array):
if r = Arr and s = Arr then

return(yes)  
else
return(No)
fi:
end proc:
n:=m;
RownColumn(n);

                                                                       No
 

oh i see now what you meant " with(ArrayTools)".

 

Thanks Doug
 


 

oh i see now what you meant " with(ArrayTools)".

 

Thanks Doug
 


 

Am sorry but i do not know what you mean by with?

Am sorry but i do not know what you mean by with?

Why do i get this error and how can i fix it??

RownColumn:=proc(n)
local m, en, q, w,r,s:
m:=n:
en:=min(op(1,m)):
with(ArrayTools):
q:=AddAlongDimension(m,1):

w:=AddAlongDimension(m,2):

r:=convert(q,Array):
s:=convert(w,Array):
if (r and s) = Array(1..en,fill = 1) then
return(yes)  
else return(No)
fi:
end proc:
n:=m;
RownColumn(n);

Error, (in RownColumn) invalid input: `convert/Array` expects its 1st argument, A, to be of type {Array, Matrix, Vector, array, list, listlist}, but received AddAlongDimension(Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 1, (1, 4) = 0, (2, 1) = 1, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 1, (4, 1) = 0, (4, 2) = 1, (4, 3) = 0, (4, 4) = 0}), 1)
 

Why do i get this error and how can i fix it??

RownColumn:=proc(n)
local m, en, q, w,r,s:
m:=n:
en:=min(op(1,m)):
with(ArrayTools):
q:=AddAlongDimension(m,1):

w:=AddAlongDimension(m,2):

r:=convert(q,Array):
s:=convert(w,Array):
if (r and s) = Array(1..en,fill = 1) then
return(yes)  
else return(No)
fi:
end proc:
n:=m;
RownColumn(n);

Error, (in RownColumn) invalid input: `convert/Array` expects its 1st argument, A, to be of type {Array, Matrix, Vector, array, list, listlist}, but received AddAlongDimension(Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 1, (1, 4) = 0, (2, 1) = 1, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 1, (4, 1) = 0, (4, 2) = 1, (4, 3) = 0, (4, 4) = 0}), 1)
 


 

M:=Matrix([[1,2,3],[2,3,4],[3,7,5]]);
                                   [1    2    3]
                                   [           ]
                              M := [2    3    4]
                                   [           ]
                                   [3    7    5]

what if i wanted to work out the diagonal from the other side. For example

 

3+3+3 = 9
2+2 = 4

1 = 1

4 +7 = 11

5 = 5

Is that possible?
The func with(MTM):=Diag works it out the normal way i want it to do it the other way.
1+3+5 = 9 -> diag(m)
2+4=6 -> diag(m,1)
2+7= -> diag(m,-1)
 

1 2 3 4 5 6 7 Last Page 1 of 9