Demonstration program for using CAS with PPL
|
12-18-2013, 05:46 PM
(This post was last modified: 01-10-2014 01:19 AM by Michael de Estrada.)
Post: #1
|
|||
|
|||
Demonstration program for using CAS with PPL
The program is probably of little interest to most people on this forum, and is meant to demonstrate usage of CAS functions and operations in PPL programs.
1. The best way I've found to incorporate CAS functions, commands and operations inside a PPL program is to first develop and debug them inside the CAS view and then enclose them in a CAS shell, i.e. <CAS Expression> becomes CAS(" <CAS Expression> ") inside a PPL program. 2. Make sure any variables that are used with a CAS function are global, either by using predefined variables such as A, B, C etc. or by defining them as either global User variables or CAS variables. Never use LOCAL variables or dummy parameters. 3. Avoid using CAS functions if a non-CAS alternate is available. For example, instead of using sqrt(), use ()^.5. PHP Code: //Eigenvalue solver for root based on guess "G". The guess should be a positive Revised code to correct misassignment of complex output from nSolve to real global variable X. Replaced X with global complex variable Z0 and then assigned its absolute value (scalar magnitude) to X. Note that the imaginary part of Z0 is approximately zero. Revised code to use AAngle instead of HAngle to set angle mode in program and then restore AAngle setting in current active App. AAngle has priority over HAngle. Revised code to add limiting case solution for rigid supports (k-->infinity). A rigid support is flagged by entering the stiffness value k as a negative number. Previously, the stiffness value k had to be entered as a very large positive value. |
|||
01-18-2014, 01:46 AM
(This post was last modified: 01-21-2014 09:05 PM by Han.)
Post: #2
|
|||
|
|||
RE: Demonstration program for using CAS with PPL
Here's a modification of your code to use only local variables. Moreover, after the program is finished, you won't be left with a lot of temporary CAS variables of the form \( a_{ij\underline{ }} \) active in the CAS view. Lastly, no global variables are altered in the process.
The idea is that since the command will ultimately be delimited by double quotes, then we can use local variables and string addition to do any intermediate calculations which do not actually involve CAS commands. The string manipulation can then be saved as a local variable. So using CAS(locavariable) is fine because the CAS() command itself is a non-CAS command, so it can handle local variables. If localvariable is a string, then all is well. PHP Code: EXPORT Beam2_Solve(matrix,guess) Graph 3D | QPI | SolveSys |
|||
01-19-2014, 06:00 PM
Post: #3
|
|||
|
|||
RE: Demonstration program for using CAS with PPL
Your modification has one serious drawback; namely you can't run Beam2_Solve directly, since the parameter matrix has to be evaluated each time the program is run. The reason I wrote the program that way and exported Beam2_Solve was to permit initial entry of the matrix parameters through Beam2_Main to obtain an initial root, and then run Beam2_Solve repeatedly to obtain additional roots w/o having to re-enter all the beam parameters, which don't change. This is why I chose to make the matrix a global CAS variable. I agree, however, that it wasn't necessary to make the individual matrix coefficients into permanent CAS variables.
|
|||
01-21-2014, 05:05 AM
(This post was last modified: 01-21-2014 05:05 AM by Han.)
Post: #4
|
|||
|
|||
RE: Demonstration program for using CAS with PPL
Oh, I misunderstood the use of m0, then. I thought it was just a temporary result, so I took it to the extreme and made everything local variables. :-)
I adjusted the code to enable users to save the matrix as any CAS variable in the main program, or they can choose to also not save the result (by pressing [Esc]). Beam2_Solve() will still work whether or not the parameter 'matrix' is a string. I suppose it still has a minor drawback in that now you have to also specify which matrix to use when doing repeated calls. Graph 3D | QPI | SolveSys |
|||
01-21-2014, 02:48 PM
(This post was last modified: 01-21-2014 04:21 PM by Michael de Estrada.)
Post: #5
|
|||
|
|||
RE: Demonstration program for using CAS with PPL
(01-21-2014 05:05 AM)Han Wrote: I adjusted the code to enable users to save the matrix as any CAS variable in the main program, or they can choose to also not save the result (by pressing [Esc]). Beam2_Solve() will still work whether or not the parameter 'matrix' is a string. I suppose it still has a minor drawback in that now you have to also specify which matrix to use when doing repeated calls. When running Beam2_Main, I get the error "bad argument type" after entering the matrix name from the command line. The program halts, and the results are not output. The matrix does get created, so the problem occurs someplace after that point. The matrix name is entered with double quotes, and if I remove them the error becomes "invalid dimension." Also, you cannot enter the matrix name from the program console, because it won't accept a string and I get "invalid input." It does work, however, if I run Beam2_Solve from the command line and enter the existing matrix name with double quotes. Edit: I found the problem. You added the string variable "m" for the matrix, which conflicted with the mass dummy parameter "m". When computing the variable s2, this caused the bad argument type error. Changing the dummy parameter "m" to "mass" resolves this problem. |
|||
01-21-2014, 04:38 PM
Post: #6
|
|||
|
|||
RE: Demonstration program for using CAS with PPL
Quote:Edit: I found the problem. You added the string variable "m" for the matrix, which conflicted with the mass dummy parameter "m". When computing the variable s2, this caused the bad argument type error. Changing the dummy parameter "m" to "mass" resolves this problem. My apologies -- I went ahead and changed the source to use 'matname' Graph 3D | QPI | SolveSys |
|||
01-21-2014, 04:42 PM
Post: #7
|
|||
|
|||
RE: Demonstration program for using CAS with PPL
(01-21-2014 04:38 PM)Han Wrote:Quote:Edit: I found the problem. You added the string variable "m" for the matrix, which conflicted with the mass dummy parameter "m". When computing the variable s2, this caused the bad argument type error. Changing the dummy parameter "m" to "mass" resolves this problem. No problem. I think you forgot to change m to matname in a few places. |
|||
01-21-2014, 05:03 PM
(This post was last modified: 01-21-2014 05:37 PM by Michael de Estrada.)
Post: #8
|
|||
|
|||
RE: Demonstration program for using CAS with PPL
I also revised my original code to replace the 16 individual matrix coefficients aij_ with four row variables row1 through row4, which reduces the number of CAS variables from 16 to 4 and simplifies the code:
PHP Code: //Eigenvalue solver for root based on guess "G". The guess should be a positive Ironically, this is the way I formulated my original RPL solution: EQ <<COEF 'MAT' {1,1} ROW1 ROW2 ROW3 ROW4 MAT DET ROT ROT DROP2>> where the coefficients A,B,C,D are created by: COEF <<LAM SIN 'SSL' STO LAM COS 'CCL' STO LAM SINH 'SHL' STO LAM COSH 'CHL' STO LAM 3 ^ 'L3' STO>> and I used user flags 1 through 4 to identify the rigid support cases, for example: ROW1 << IF 1 FC? THEN L3 NEG PUTI K1 PUTI L3 PUTI K1 PUTI ELSE 0 PUTI 1 PUTI 0 PUTI 1 PUTI END >> I'm changing the RPL code to use negative values instead of flags to designate rigid supports e.g. 1 FC? becomes K1 0 >= |
|||
01-21-2014, 09:04 PM
Post: #9
|
|||
|
|||
RE: Demonstration program for using CAS with PPL
(01-21-2014 04:42 PM)Michael de Estrada Wrote:(01-21-2014 04:38 PM)Han Wrote: My apologies -- I went ahead and changed the source to use 'matname' Indeed my sloppiness knows no bounds ;_; Graph 3D | QPI | SolveSys |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)