hi,
in the code in
this program the function adj(m) works well with numbers like
but returns a "bad argument type" error with symbolic values like
.
Why?
The need to have this function is because the new adjoint_matrix() in the CAS is, as it must be, more detailed, and it returns characteristic polynomial of A and the comatrix o A-xI, i.e.
Code:
adjoint_matrix([1,2],[4,3]);
[[1, -a-d, a*d-b*c], [ [[1],[0]], [[-d,b],[c,-a]] ] ]
that's correct, but isn't the simple desired form (only TRN(cofactors(mat)) ):
Any help, please, using (or not) the new adjoint_matrix()?
Salvo
It is true! was there a change in interactivity HP PPL - CAS?
There should not have been, so this is interesting and exactly why we wanted a more public beta to test a wider range of user programs.
To be clear, you are calling your function in the CAS where previously it worked fine? Or are you calling it from Home?
Please provide exact steps that DID work in prior versions and now no longer work. Thank you!
(11-10-2017 04:41 PM)Tim Wessman Wrote: [ -> ]There should not have been, so this is interesting and exactly why we wanted a more public beta to test a wider range of user programs.
To be clear, you are calling your function in the CAS where previously it worked fine? Or are you calling it from Home?
Please provide exact steps that DID work in prior versions and now no longer work. Thank you!
I called my adj() in CAS with this code:
that should return
\[ \begin{Vmatrix}
d & -b \\
-c & a
\end{Vmatrix} \]
and instead return an error.
If I try
I get correctly
\[
\begin{Vmatrix}
3 & -2 \\
-4 & 1
\end{Vmatrix}
\]
In my program adj(m) recall the internal cofactors(m) that use MAKEMAT and an internal function, minor(mat, r,c) that simply use delrows() and delcols() to delete row r and col c and pass the argument, and so on.
A simple code that, if I well remember worked well with numbers and with letters first (however I can be wrong, I don't remember if in older version it worked also with letters, I would like to understand why the littoral matrix is taken as it wouldn't a matrix and why then there is the "bad argument type")...
Also in iOS app I get the error. So I wonder: maybe it's not a real bug but only a problem with types of vars?
Simply, I thought that passing a matrix (m) it were indifferent if the matrix had numbers or letters (for symbolic calc) in its elements...
EDIT: also with adj([[1, SIN(x)],[2,3]]) I get "Error: Bad argument type"
\[
\begin{Vmatrix}
1 & sin(x) \\
2 & 3
\end{Vmatrix}
\]
Here there is the code, if someone would like to collaborate to find the error in it, that prevent the use of a letters instead of numbers in the matrix:
Code:
minor();
EXPORT cofactors(m)
// Cofactors of the matrix m
BEGIN
local tempmat, cofact, deter;
local r, c, j, k;
r:=rowDim(m);
c:=colDim(m);
cofact:= MAKEMAT(0,r,c);
tempmat:= m;
FOR j FROM 1 TO r DO
FOR k FROM 1 to c DO
cofact:= minor(m, j, k);
deter:= ((-1)^(j+k)) * det(cofact);
tempmat(j,k):= deter;
END; // inner for
END; //for
RETURN tempmat;
END;
minor(mat, r,c)
// Returns the matrix without row r and col c
BEGIN
mat:= delrows(mat,r);
mat:= delcols(mat,c);
RETURN mat;
END;
EXPORT adj(m)
// adjoint matrix (=transpose of cofactors(m))
BEGIN
local ad;
ad:= cofactors(m);
RETURN TRN(ad);
END;
The problem is in input, I suppose:
type([1,2],[4,3]) -> DOM_LIST
TYPE([1,2],[4,3]) -> 4
(matrix)
but
type([1,sin(x)],[2,3]) -> DOM_LIST
TYPE([1,sin(x)],[2,3]) -> 6
(list)
...
(11-10-2017 04:57 PM)salvomic Wrote: [ -> ]I called my adj() in CAS with this code:
that should return
Well, that is the issue. Did it work previously and something has changed? Or is this just new code not working like you'd want.
One is a bug and one is an enhancement/feature request.
(11-10-2017 06:47 PM)Tim Wessman Wrote: [ -> ]Well, that is the issue. Did it work previously and something has changed? Or is this just new code not working like you'd want.
One is a bug and one is an enhancement/feature request.
Tim, I'm not requesting an enhancement, hi :-)
I made the code in 2015 and then it worked, I believe also with the symbolic matrices...
Now that code (I haven't changed nothing) distinguishes between matrices and lists and refuses to treat the second ones.
I do *hope* it isn't a bug
When you compute the det of a minor, it will return a symbolic expression, can you really store that in a Home local variable?
Why don't you write a CAS program ?
What about defining adj(m):=adjoint_matrix(m)[2,size(m)]?
(11-10-2017 06:55 PM)parisse Wrote: [ -> ]When you compute the det of a minor, it will return a symbolic expression, can you really store that in a Home local variable?
you are right, I didn't think it when I wrote the program.
Quote:Why don't you write a CAS program ?
What about defining adj(m):=adjoint_matrix(m)[2,size(m)]?
oh, well (it is not a bug, Tim)
In 2015 we hadn't adjoint_matrix()...
Thank you! Now is more and more simple. I'm rewriting the program as you suggest.
Only a little difference: adjoint_matrix([[1,2],[4,3]])[2,2] returns [[-3,2],[4,-1]] and my adj([[1,2],[4,3]]) returns [[3,-2],[-4,1]], that's the first result multiplied by -1 ...
Also with [[a,b],[c,d]] I get the difference * -1...
Then adj(m):=adjoint_matrix(m)[2,size(m)]*(-1)^(size(m)-1) should do the job.
(11-10-2017 07:09 PM)parisse Wrote: [ -> ]Then adj(m):=adjoint_matrix(m)[2,size(m)]*(-1)^(size(m)-1) should do the job.
ok!
I'll rewrite the whole program for the new FW as a CAS function...
EDIT
This code is all CAS and works after the beta 2017 November 8.
adj(m) Adjoint matrix
cofactors(m) Cofactors matrix -> TRN(adj(m))
minor(m, r, c) a minor of the matrix m, suppressing row r and col c
Code:
// Cofactors matrix
// use programs adj(m) and minor(m,r,c)
#cas
cofactors(m) :=
BEGIN
RETURN TRN(adj(m));
END;
#end
#cas
// Adjoint of a matrix (transpose of cofactor mat)
// after beta 2017 Nov 8
adj(m) :=
BEGIN
RETURN adjoint_matrix(m)[2,size(m)]*(-1)^(size(m)-1);
END;
#end
#cas
// Minor of a matrix
// r row, c col to suppress
minor(m, r,c) :=
BEGIN
m:= delrows(m,r);
m:= delcols(m,c);
RETURN m;
END;
#end