Need CAS help - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: Need CAS help (/thread-255667.html) Need CAS help - Michael de Estrada - 11-12-2013 Using CAS in programs is tricky. I need to store a value inside a CAS variable inside a program using variables local to the program or passed as parameters to the program, I've tried using the CAS command to no avail, since it evaluates to zero. Assuming aaaa is a CAS variable and A,B,C are variables than have been assigned non-zero numeric values CAS("aaaa:=A*B*C") stores zero in aaaa, but CAS("aaaa:=2") stores the number 2. Also, if I store 2 in aaaa directly in CAS, it successfully retains this value in the program. So, basically, there seems to be no way to store computed values in a program in a CAS variable. Re: Need CAS help - Han - 11-12-2013 Quote: Using CAS in programs is tricky. I need to store a value inside a CAS variable inside a program using variables local to the program or passed as parameters to the program, I've tried using the CAS command to no avail, since it evaluates to zero. Assuming aaaa is a CAS variable and A,B,C are variables than have been assigned non-zero numeric values CAS("aaaa:=A*B*C") stores zero in aaaa, but CAS("aaaa:=2") stores the number 2. Also, if I store 2 in aaaa directly in CAS, it successfully retains this value in the program. So, basically, there seems to be no way to store computed values in a program in a CAS variable. You keep forgetting that the CAS currently does not recognize local variables. So CAS("aaaa:=A*B*C") actually creates a GLOBAL variable called aaaa and this GLOBAL variable will have the correct value. However, since local variables have higher priority, the LOCAL variable aaaa still has a value of 0 and that is what is visible to the program. So to do what you want, use: aaaa:=CAS("A*B*C"); which takes the result of the CAS calculation A*B*C and saves it into the LOCAL variable aaaa.Edited: 12 Nov 2013, 8:42 p.m. Re: Need CAS help - Michael de Estrada - 11-12-2013 Thanks, but that doesn't solve my problem. It just creates a nul value in aaaa. I need this to be a CAS value not a local value. Oh dear, now my calculator has crashed again, and I've lost my CAS history, variables, settings... What a pain this thing is to do anything. Edited: 12 Nov 2013, 9:26 p.m. Re: Need CAS help - Han - 11-12-2013 Quote: Thanks, but that doesn't solve my problem. It just creates a nul value in aaaa. I need this to be a CAS value not a local value. Oh dear, now my calculator has crashed again, and I've lost my CAS history, variables, settings... What a pain this thing is to do anything. Are the variables aaaa, A, B,and C all global variables? or are they all local variables? or a mix? This makes a big difference. If you are using A, B, and C as local variables, then that would not work in CAS. In general, I try to avoid using the built-in variables as local variables. Are you using EXPORT on aaaa or did you leave that out? I am able to create a CAS variable just fine with ```EXPORT TEST() BEGIN CAS("aaaa:=A*B*C"); END; ``` When I go into the memory browser, I see aaaa listed as a real value under the CAS variables. Its value is non-zero, provided that my A, B, and C built-in variables are non-zero. Perhaps there are details I am not understanding about your code. Edited: 12 Nov 2013, 10:02 p.m. Re: Need CAS help - Michael de Estrada - 11-12-2013 I'm afraid my calculator is broken again and may need another re-format, so I may just throw it out with tomorrow's trash pickup and cut my losses. Re: Need CAS help - cyrille de BrĂ©bisson - 11-13-2013 Hello, export test(A,B,C) begin CAS.abcd:=A+B+C; end; seems to work. But I am not sure if it will work on your earlier revision. Can you please try it? Else, you might want to try export test(A,B,C) begin D:= A*B*C; // note the use of a GLOBAL temporary variable. you could use an exported variable also CAS("abcd:=D"); end; for your locking machine. did you try rebooting with backspace pressed? it might be enough to restart it. then erase the offending files... Cyrille Re: Need CAS help - Michael de Estrada - 11-13-2013 Well, I've finally gotten everything to work, but it hasn't been easy. As you can see, my dilemma was getting CAS and non-CAS stuff to work together harmoniously inside a program. I'm creating and solving a symbolic expression, which contains coefficients that are evaluated at runtime to be used in the construction of the expression. All of this would be so much easier if there were some sort of CAS switch that could be enabled inside a program at runtime, i.e. CASmode(On || Off). Anyways, here's the code I've written; note the complete absence of LOCAL variables: Program Beam ```//Eigenvalue solver for root based on guess "G" //The guess should be a positive number slightly larger than the lowest non-trivial (zero) //root. If it is too low, the result will be a very small number representing zero. Once the lowest //root is determined, the program can be run again w/o entering the beam data again to //determine additional higher roots if needed, which will be stored in the matrix variable M0. //Note that the natural frequencies are proportional to the square of the eigenvalues. EXPORT Beam_Solve(guess) BEGIN G:=guess; CAS("M0:=nSolve(DET(m1)=0,x=G)"); RETURN M0; END; //This program solves for the natural frequencies of a beam with flexible end supports EXPORT Beam_Main(k1,k2,k3,k4,EI,m,L,guess) BEGIN //Dimensionless coefficients A:=k1*L^3/EI; B:=k2*L/EI; C:=k3*L^3/EI; D:=k4*L/EI; //Create CAS matrix elements CAS("a11_:=x^3"); CAS("a12_:=-A"); CAS("a13_:=-x^3"); CAS("a14_:=-A"); CAS("a21_:=-B"); CAS("a22_:=-x"); CAS("a23_:=-B"); CAS("a24_:=x"); CAS("a31_:=-x^3*COS(x)-C*SIN(x)"); CAS("a32_:=x^3*SIN(x)-C*COS(x)"); CAS("a33_:=x^3*COSH(x)-C*SINH(x)"); CAS("a34_:=x^3*SINH(x)-C*COSH(x)"); CAS("a41_:=-x*SIN(x)+D*COS(x)"); CAS("a42_:=-x*COS(x)-D*SIN(x)"); CAS("a43_:=x*SINH(x)+D*COSH(x)"); CAS("a44_:=x*COSH(x)+D*SINH(x)"); //Create CAS eigenvalue matrix CAS("m1:=[[a11_,a12_,a13_,a14_],[a21_,a22_,a23_,a24_],[a31_,a32_,a33_,a34_],[a41_,a42_,a43_,a44_]]"); //Solve for eigenvalue based on guess Beam_Solve(guess); //Calculate natural frequency in Hz L0:=sqrt(EI/m)*(M0/L)^2/(2*pi); //Print eigenvalue and natural frequency RETURN {M0,L0}; END; ``` Edited: 13 Nov 2013, 3:51 p.m.