Need CAS help « Next Oldest | Next Newest »

 ▼ Michael de Estrada Posting Freak Posts: 1,665 Threads: 142 Joined: Jan 2009 11-12-2013, 07:47 PM 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. ▼ Han Senior Member Posts: 709 Threads: 104 Joined: Nov 2005 11-12-2013, 08:41 PM 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. ▼ Michael de Estrada Posting Freak Posts: 1,665 Threads: 142 Joined: Jan 2009 11-12-2013, 09:22 PM 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. ▼ Han Senior Member Posts: 709 Threads: 104 Joined: Nov 2005 11-12-2013, 09:59 PM 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. ▼ Michael de Estrada Posting Freak Posts: 1,665 Threads: 142 Joined: Jan 2009 11-12-2013, 10:30 PM 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. Michael de Estrada Posting Freak Posts: 1,665 Threads: 142 Joined: Jan 2009 11-13-2013, 03:24 PM 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. cyrille de Brébisson Member Posts: 193 Threads: 10 Joined: Mar 2008 11-13-2013, 01:29 AM 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

 Possibly Related Threads... Thread Author Replies Views Last Post HP Prime: CAS taylor Alberto Candel 5 2,549 12-13-2013, 09:45 PM Last Post: Alberto Candel HP Prime CAS curiosity bluesun08 11 3,299 12-10-2013, 01:03 PM Last Post: Han [HP-Prime CAS] "Warning, ^ (Command) Is ambiguous on non square matrices"?? CompSystems 1 1,429 12-07-2013, 07:15 PM Last Post: CompSystems HP Prime: complex numbers in CAS. Alberto Candel 1 1,246 12-06-2013, 02:36 PM Last Post: parisse [HP Prime] plotfunc() bug in CAS Chris Pem10 2 1,503 12-04-2013, 02:46 PM Last Post: Chris Pem10 HP Prime: Home/CAS? Alasdair McAndrew 11 2,626 11-26-2013, 02:48 PM Last Post: Alberto Candel HP Prime numerical precision in CAS and HOME Javier Goizueta 5 1,580 11-16-2013, 03:51 AM Last Post: Paul Dale HP Prime - CAS functions in Spreadsheet App CR Haeger 6 1,675 11-11-2013, 12:37 AM Last Post: Michael de Estrada Another HP Prime CAS question Michael de Estrada 3 1,248 11-09-2013, 10:56 AM Last Post: Michael de Estrada Trig vs hyperbolic handling differences in Prime CAS Michael de Estrada 3 1,168 11-08-2013, 06:26 PM Last Post: Mark Hardman

Forum Jump: