This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
prime:cashome [2017/10/30 08:10] webmasterpdx |
prime:cashome [2017/11/06 23:44] (current) webmasterpdx |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== CAS vs Home ====== | ||
+ | CAS is designed to calculate things symbolically, | ||
+ | |||
+ | To use a conventional numerical loop, don't use CAS. In this case, go to home mode and use the Σ symbol from the math template key....as in Σ(1/ | ||
+ | |||
+ | Just remember the rule that CAS is trying to solve symbolically, | ||
+ | |||
+ | Generally speaking, if an algorithm is put together using CAS commands, and a Home program is put together using Home commands to run the same algorithm, then the Home program will run faster. There are some CAS commands whereby a single command executes a full loop. In those cases, the CAS command will run faster than the loop in the Home Program. | ||
+ | |||
+ | In CAS, it is best to always use * when you mean it. e.g. 2*x, a*x, etc.. You can get away with using 2x (a number multiplied by a variable), but never with 2 variables, as it will see ax as a single variable called ' | ||
+ | |||
+ | Also, understand that when using variables in an expression, if that variable has a value assigned to it, CAS may be using that value, instead of solving it symbolically. You can remove the variable from being defined using the purge() function. The restart command purges all the CAS variables. | ||
+ | |||
+ | Some CAS functionality can be assisted by telling the system some characteristics about the variables involved, using the assume() and additionally() functions. The function about(var) returns any assumptions on the variable. Purging the variable removes any assumptions. e.g. To get the integral of e^(-a*x) from 0 to infinity will return undef unless you say assume(RE(a)> | ||
+ | |||
+ | Sometimes, CAS will state something cryptic about how it's answer may not be perfect and when you hit enter again, it then gives you it's answer. This is because some math can be complex and it's trying to tell you what it knows. Don't let these statements worry you. It's just the CAS system being complete. | ||
+ | |||
+ | Make sure you read the help docs for the about, purge, assume and additionally commands. | ||
+ | |||
+ | There are unusual ops that will get translated into functions when you manually enter them, but it's good to learn them as they can allow you faster entry. e.g. a+=3 gets translated to increment(a, | ||
+ | |||
+ | Any variable assigned in Home mode or in a Home Program is a Home Variable. Likewise any variable assigned in CAS mode or in a CAS Program is a CAS Variable. Indexing in HP Basic into Home Variables is done using () braces, as in L1(5). With CAS Variables, () can be used with a constant index in read only mode, but when a variable index is used, due to parsing issues (it thinks l1(x) is a function call), you must use [] braces instead, as in l1[i]. So, it is recommended when using CAS variables, it is best to use [] to index always. This applies to Lists, Matrices and Vectors (1D Matrix). In XCas, lists, matrices and vectors are all lists. Note that XCas uses [] always anyway, so this keeps the Prime' | ||
+ | |||
+ | Global variables can be made from Home and CAS modes manually. From a program, global variables are made by not declaring the name as LOCAL and just assigning a value. However, the program type from which it's defined determines if it's a CAS or a Home variable. e.g. If in a CAS program you defined m: | ||
+ | |||
+ | In Home mode, to return multiple values, return it as a list. e.g. f1(x) returns a list containing 3 integers. The values returned can be assigned to variables like this: L: | ||
+ | In CAS mode, you can do {A, | ||
+ | Note that from Home mode the CAS function sto(f1(x), | ||
+ | |||
+ | If you define a CAS program using the #CAS...#END directives in a mixed mode program (mixture of Home and CAS functions) and compile it by closing the program editor, then if you delete the function later in the program editor, it does not delete the program from the CAS point of view. You still have to use Shift-Toolbox/ | ||
+ | |||
+ | To remove characters from a string, you can use S: | ||
+ | < | ||
+ | // Drop chars from string. | ||
+ | // S | ||
+ | // L Pos of leftmost char before deletion. | ||
+ | // R Pos of first char on right after deletion. | ||
+ | EXPORT STRDEL(S, | ||
+ | BEGIN | ||
+ | LOCAL N:=DIM(S); | ||
+ | RETURN IFTE(L< | ||
+ | END; // BEGIN... | ||
+ | </ | ||
+ | |||
+ | In the declaration of local variables in a CAS program, you need to keep track of priorities. e.g. local a:=1;b:=0; in a Home program is interpreted as local (a: | ||
+ | |||
+ | There are some more tips in [[http:// | ||
+ | |||
+ | |||