Bad argument type, DET(M9)/M8(2,1) in App - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Bad argument type, DET(M9)/M8(2,1) in App (/thread-5521.html) Bad argument type, DET(M9)/M8(2,1) in App - toshk - 01-14-2016 11:04 AM eg1. how([1,4,3,2,1,4,4])--> Error: Bad argument type, M0(B,A):=-DET(M9)/M8(2,1) cant be executed. eg2. how([1,4,k,2,1,4,4])-> expecting [1,k,1,4] into M0 but Error: Bad argument type Code: ``` #pragma mode( separator(.,;) integer(h32) ) exc(); dett(); #cas how(den):= //"Error: Bad argument type if variable say k is insert into the vector den" BEGIN n:=length(den); m:=length(den); nx:=simplify(poly2symb(den)); IF even(n-1) THEN rw:=((n-1)/2)+1; ELSE rw:=(n)/2 END; M0:=makemat(n,rw); c:=0; WHILE n>0 DO     a:=1;L1:={};c:=c+1;     IF n==0 THEN               L1(a):=coeff(nx,n);              ELSE        nl:=n-1;        FOR j FROM c TO length(den) STEP 2 DO            L1(a):=coeff(nx,x,nl); // "Error: Bad argument type"            a:=a+1;            nl:=nl-2;        END;               END;     L2(n):=length(L1);     FOR j FROM 1 TO length(L1) DO         M0(c,j):=L1(j);     END; n:=n-1; END; hw:=M0; exc(); END; #end #cas   exc() BEGIN FOR j FROM 1 TO m-2 DO     k:=j+1;     B:=j;     M8:=subMat(M0,j,1..rw,k,1..rw);     dett(); END; END; #end #cas  dett() BEGIN //M9:=subMat(M8,1,1,2,2); M9:=matrix(2,2); B:=B+2; A:=1;     FOR j FROM 2 TO rw DO         M9(1,1):=M8(1,1);         M9(2,1):=M8(2,1);         M9(1,2):=M8(1,j);         M9(2,2):=M8(2,j);             M0(B,A):=-DET(M9)/M8(2,1); //"Error: Bad argument type"         A:=A+1;     END; END; #end``` RE: Bad argument type, DET(M9)/M8(2,1) in App - cyrille de brébisson - 01-15-2016 07:43 AM Hello, The problem here is that the result of the -DET(M9)/M8(2,1) is not a number, it's a fraction. And this symbolic object can not be stored in a purely numerical 'Home) matrix (M0). Your program does mix CAS and Home, which, despite being ok in lots of cases, can sometimes lead to strange things. My #1 advice would be to use CAS variables rather than home variables for your CAS programs. If you do want to store the data in a home variables, add an evalf around the -DET(M9)/M8(2,1) code: M0(B,A):=evalf(-DET(M9)/M8(2,1)); and it should work. cyrille RE: Bad argument type, DET(M9)/M8(2,1) in App - toshk - 01-15-2016 10:48 AM (01-15-2016 07:43 AM)cyrille de brébisson Wrote:  Hello, The problem here is that the result of the -DET(M9)/M8(2,1) is not a number, it's a fraction. And this symbolic object can not be stored in a purely numerical 'Home) matrix (M0). Your program does mix CAS and Home, which, despite being ok in lots of cases, can sometimes lead to strange things. My #1 advice would be to use CAS variables rather than home variables for your CAS programs. If you do want to store the data in a home variables, add an evalf around the -DET(M9)/M8(2,1) code: M0(B,A):=evalf(-DET(M9)/M8(2,1)); and it should work. cyrille ..Thanks Cyrille, there is problem of defining a especially matrix under CAS variables....say , M25:=makemat(n,rw); FOR j FROM 1 TO length(L1) DO M25(c,j):=L1(j); END; Prime seems to have a hard time defining M25 as a matrix, instead it defines M25 as a function(M25(c,j)). hence i am forced to used Home variables M0 instead which would not work on how([1,4,k,2,1,4,4]) containing a variable k for symbolic manipulation under CAS. RE: Bad argument type, DET(M9)/M8(2,1) in App - Han - 01-15-2016 05:13 PM (01-15-2016 10:48 AM)toshk Wrote:   (01-15-2016 07:43 AM)cyrille de brébisson Wrote:  Hello, The problem here is that the result of the -DET(M9)/M8(2,1) is not a number, it's a fraction. And this symbolic object can not be stored in a purely numerical 'Home) matrix (M0). Your program does mix CAS and Home, which, despite being ok in lots of cases, can sometimes lead to strange things. My #1 advice would be to use CAS variables rather than home variables for your CAS programs. If you do want to store the data in a home variables, add an evalf around the -DET(M9)/M8(2,1) code: M0(B,A):=evalf(-DET(M9)/M8(2,1)); and it should work. cyrille ..Thanks Cyrille, there is problem of defining a especially matrix under CAS variables....say , M25:=makemat(n,rw); FOR j FROM 1 TO length(L1) DO M25(c,j):=L1(j); END; Prime seems to have a hard time defining M25 as a matrix, instead it defines M25 as a function(M25(c,j)). hence i am forced to used Home variables M0 instead which would not work on how([1,4,k,2,1,4,4]) containing a variable k for symbolic manipulation under CAS. Use M25[c,j]:=L1(j) instead. From a syntax point of view, no one would know whether you are creating a CAS function named M25 or if you are referring to the cell of a matrix named M25 because the syntax looks exactly the same. Therefore, to avoid ambiguity, use the square brackets for matrices since functions cannot be defined using square brackets. RE: Bad argument type, DET(M9)/M8(2,1) in App - toshk - 01-16-2016 06:54 AM (01-15-2016 05:13 PM)Han Wrote:   (01-15-2016 10:48 AM)toshk Wrote:  ..Thanks Cyrille, there is problem of defining a especially matrix under CAS variables....say , M25:=makemat(n,rw); FOR j FROM 1 TO length(L1) DO M25(c,j):=L1(j); END; Prime seems to have a hard time defining M25 as a matrix, instead it defines M25 as a function(M25(c,j)). hence i am forced to used Home variables M0 instead which would not work on how([1,4,k,2,1,4,4]) containing a variable k for symbolic manipulation under CAS. Use M25[c,j]:=L1(j) instead. From a syntax point of view, no one would know whether you are creating a CAS function named M25 or if you are referring to the cell of a matrix named M25 because the syntax looks exactly the same. Therefore, to avoid ambiguity, use the square brackets for matrices since functions cannot be defined using square brackets. ....thanks Han!!