
×InformationFix Windows 10 Update Issues
Resolve Windows 10 related issues for your HP computers or printers by HP Windows 10 Support Center

×InformationFix Windows 10 Update Issues
Resolve Windows 10 related issues for your HP computers or printers by HP Windows 10 Support Center
 HP Community
 >
 Other Products
 >
 Calculators
 >
 Problems with local variables in Cas programs
 Mark Topic as New
 Mark Topic as Read
 Float this Topic for Current User
 Bookmark
 Subscribe
 Mute
 Printer Friendly Page
Create an account on the HP Community to personalize your profile and ask a question
Problems with local variables in Cas programs
05022018 09:30 AM  edited 05072018 09:48 AM
Hello everyone,
I have trouble with my CAS program, it seems there's a problem with some local variables.
This is the program:
#cas
newmult(varx):=
BEGIN
LOCAL varv,xvnm,jac,fun,jacev,funev;
LOCAL J,L,M,M1,M2,M3,M4;
varv:=[varx];
M3:=varv(3);
M:=SIZE(varv(3));
L:=varv(4);
M1:=[[0]];
REDIM(M1,{L+1,M});
M4:=[0];
REDIM(M4,L+1);
M1(1):=M3;
xvnm:=varv(2)=varv(3);
jac:=TRN(diff(varv(1),varv(2)));
fun:=varv(1);
FOR J FROM 1 TO L DO
jacev:=subst(jac,xvnm);
funev:=subst(fun,xvnm);
//IT SEEMS THE PROBLEM LIES IN THE NEXT LINE
M2:=−1*(jacev^(−1))*funev;
M3:=M3+M2;
M1(J+1):=M3;
M4(J+1):=l2norm(M2);
xvnm:=varv(2)=M3;
END;
ADDCOL(M1,M4,M+1);
EDITMAT(M1,"RESULTS");
return jac;
END;
#end
So the problem is this:
M2:=−1*(jacev^(−1))*funev;
The input should be something like this:
([x^210*x+y^2+8 , x*y^2+x10*y+8],[x, y],[0,0],4)
I deleted command LOCAL and the program worked well, however when I use the command LOCAL an error message appears ("Error: Bad Argument Value"). Also, when I delete only M2 in the Local command, the program works well; that means that there's no problem when M2 is a global variable.
I don't want to delete the LOCAL command neither make M2 a global variable. So, what's the problem or what should I do?
I have some other questions about the CAS programs like: Is it possible to use the IF command or the IFERR command in the CAS programs? How shoild I use them? What commands are not allowed in these programs?
Thanks for your answers.
05072018 04:36 AM
Hello dj2631,
Can you tell us what your input is?
It is difficult to find a bug without knowing what the input is!
It would even better if you said something about what the program is supposed to do.
Without knowing these things I think I see a problem though.
You write:
varv:=[varx];
M3:=varv(3);
So varv has only 1 element, namely varx.
So varv(3) does not exist and will cause an error.
05072018 09:31 AM
The input should be something like this:
([x^210*x+y^2+8 , x*y^2+x10*y+8],[x, y],[0,0],4)
The only problem here is the LOCAL VARIABLE M2:
If define M2 as a LOCAL VARIABLE, an error mesage appears:
"Error: Bad Argument Value"
If I use M2 as GLOBAL VARIABLE the program works great.
05082018 11:25 AM
In my opinion there are 2 causes of problems with this input.
First I think there is a bug in the TRN command.
Second, you are doing exact calculations in CAS, which means that the matrix elements have forms like
(9234543567854356754323454350/2345676567896545673456543445656788)*SQRT(22345678987432456765436784324567654567)
After a number of loops the integers are immense, which causes an error.
You can easily prevent this by unchecking the exact box in CAS settings or by entering [0.0, 0.0] (so decimal numbers) as third argument.
Or by using approx() somewhere in the program.
I said I think that there is a bug in the TRN command.
See this:
So I think there is something wrong with the type of b and c.
This can be corrected by storing b or c into the global Home matrix M1:
Or:
There are also other ways to correct this, without using the global Home matrix M1.
When you are interested I can say something about this in another message.
You can verify that the problem is caused by the matrix jac in your program by replacing it by the matrix you know it should be.
When you do this you will probably see that the program works well.
Didn't find what you were looking for? Ask the community