HP Prime: CAS Commands in Home Mode
|
12-18-2013, 04:21 AM
Post: #1
|
|||
|
|||
HP Prime: CAS Commands in Home Mode | |||
12-18-2013, 04:54 AM
Post: #2
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
Hi Eddie,
There's an alternate approach that I prefer that preserves the CAS format and avoids all the quoting or changing from lower case to upper case. For example: zeros(r^3-6,r) in CAS view becomes CAS("zeros(r^3-6,r)") in Home view. This also works well when using CAS commands in programs. |
|||
12-18-2013, 09:48 PM
Post: #3
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
A question: Why exactly are the quotes (" ") needed? Thanks!
|
|||
12-18-2013, 09:53 PM
(This post was last modified: 12-18-2013 09:53 PM by Han.)
Post: #4
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
(12-18-2013 09:48 PM)Helge Gabert Wrote: A question: Why exactly are the quotes (" ") needed? Thanks! Arguments inside ( ) are handled as if from the Home view. So without it, the parser tries to evaluate the arguments and will error out as it is unable to evaluate undefined variables. By passing a string, the single argument then gets parsed by the CAS parser. (Yes, there are two separate parsers at the moment.) Graph 3D | QPI | SolveSys |
|||
12-19-2013, 12:17 AM
Post: #5
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
Thanks so much!
And what would be the best way to pass a function or symbolic expression to a PPL program from the home view command line? I know that defining a function in CAS view first, say a(x):=x^2+2, works - - which then can be called by the CAS(" . . . a(x) ") construct in the PPL program. Alternatively, defining F0, . . . , F9 beforehand also works with CAS("solve(F1(x),x") etc. But can I call the PPL program like TEST(X^2+2)? And have the PPL program TEST(k) . . . do something here with k, recognizing k is a function? END; That doesn't seem to work. |
|||
12-19-2013, 12:57 AM
Post: #6
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
Sure -- all you have to remember is that an unevaluated expression needs single-quoting. So you can pass an expression via:
TEST('X^2+2*X') and the program Code: TEST(k) will store the symbolic expression X^2+2*X into k. Graph 3D | QPI | SolveSys |
|||
12-19-2013, 01:06 AM
Post: #7
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
I prefer using RPN mode in Home View, but I keep getting a syntax error when
I attempt to use CAS. For example, if I enter the following expression: CAS("zeros(X^3-4)"), I get the Error: syntax error message. What am I doing wrong or does RPN mode not support CAS operations? |
|||
12-19-2013, 01:11 AM
(This post was last modified: 12-19-2013 01:11 AM by Han.)
Post: #8
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
Type:
"zeros(x^3-4)" ENTER CAS(1) In RPN mode, commands have an "argument" specifying how many stack arguments to use. Hence the CAS(1). Also, remember that when using CAS, global variables like X get replaced with their actual values. Thus, X^3-4 will result in an empty vector (no solution) since you would be equivalently solving for the zeros of a constant function. So do note the lower case x in the commands above. Graph 3D | QPI | SolveSys |
|||
12-19-2013, 01:15 AM
Post: #9
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
(12-19-2013 01:11 AM)Han Wrote: Type: Thanks Han, I didn't know that. |
|||
12-19-2013, 03:24 AM
Post: #10
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
(12-19-2013 12:57 AM)Han Wrote: Sure -- all you have to remember is that an unevaluated expression needs single-quoting. So you can pass an expression via: Yes, of course, single quotes are fine with upper case X, but you get an error if you try TEST('x^2+2*x') in home view, so you are forced to use TEST('X^2+2*X'), and then, inside the program, you cannot write something like CAS("subst(k, X='x')"), because nothing gets substututed, (only returns k), so you can't use the function with lower case 'x' for further processing with CAS commands/functions. |
|||
12-20-2013, 09:12 AM
Post: #11
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
Hello
Quote:Inside the program, you cannot write something like CAS("subst(k, X='x')"), because nothing gets substututed, (only returns k), so you can't use the function with lower case 'x' for further processing with CAS commands/functions. HAve you tried using subst(k, "X='x'"); ? this would cause numerical mode to send the value of k and a CAS compiled "X='x'" to the CAS subst command... Cyrille |
|||
12-20-2013, 10:49 PM
Post: #12
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
I will try that. Thank you for the suggestion!
|
|||
12-20-2013, 11:13 PM
(This post was last modified: 12-20-2013 11:13 PM by Helge Gabert.)
Post: #13
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
No, that doesn't work. I get the message "Syntax Error" when I check my program, and the cursor is on the first inner " of the line (the second double quote from the left)
CAS("subst(k,"X='x'")"); Anything else I can try, or do I need to write this as a "true" CAS program, and forget about calling the program from home? No, that doesn't work. I get the message "Syntax Error" when I check my program, and the cursor is on the first inner " of the line (the second double quote from the left) CAS("subst(k,"X='x'")"); Anything else I can try, or do I need to write this as a "true" CAS program, and forget about calling the program from home? No, that doesn't work. I get the message "Syntax Error" when I check my program, and the cursor is on the first inner " of the line (the second double quote from the left) CAS("subst(k,"X='x'")"); Anything else I can try, or do I need to write this as a "true" CAS program, and forget about calling the program from home? No, that doesn't work. I get the message "Syntax Error" when I check my program, and the cursor is on the first inner " of the line (the second double quote from the left) CAS("subst(k,"X='x'")"); Anything else I can try, or do I need to write this as a "true" CAS program, and forget about calling the program from home? |
|||
12-21-2013, 12:39 AM
Post: #14
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
I'm going to add spacing into your command:
CAS("subst(k," X='x' ")" ); This makes no sense. Your arguments consist of three objects (a string, the expression X='x', and another string) simply juxtaposed. The other caveat is that what you substitute must not be pre-defined. So the global variables will not work. You can verify this is CAS view by typing: subs('X^2-1', X=2) and you will see the warning. There are two approaches I know of: Code:
This method requires you use a string for the input k (e.g. TEST("x^2-1") and use non-global variables). The next method (below) uses REPLACE(). Code:
Now, try typing TEST("X^2-1"). Graph 3D | QPI | SolveSys |
|||
12-21-2013, 05:44 AM
Post: #15
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
Yes, the second method works! The first one doesn't, though.
(And I know, the last try was non-sensical, but that was what Cyrille suggested). Thanks for the tip with REPLACE! Of course, one needs to input the symbolic expression as a string, but that is OK. |
|||
12-21-2013, 05:54 AM
Post: #16
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
(12-21-2013 05:44 AM)Helge Gabert Wrote: Yes, the second method works! The first one doesn't, though. The first one only works if the input is a string, and the initial variable you used is not defined -- so no global variables for sure. So and input of "X^2-1" won't work, but "x^2-1" will. Note the lower case x in the code. And also note that x defined in Home view is different from x defined in CAS view. (So you need to make sure to delete x from the memory browser as well as use: purge(x) in the CAS view.) Graph 3D | QPI | SolveSys |
|||
12-21-2013, 06:50 AM
Post: #17
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
Alright - - but I have to say I prefer the second method - - it is a lot less cumbersome.
I enjoy the Prime (speed and color), and it is fun in interactive mode, but in comparison to the elegance of the 50G, where every object gets processed according to consistent rules, the Prime's idiosyncrasies with respect to programming symbolic expressions, constitute a step backward. |
|||
12-21-2013, 02:15 PM
Post: #18
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
(12-19-2013 01:15 AM)John Colvin Wrote:(12-19-2013 01:11 AM)Han Wrote: Type: Hi, "zeros(x^3-4,x)" [ENTER] CAS [ENTER] would do. Regards, Miguel |
|||
12-23-2013, 12:46 PM
Post: #19
|
|||
|
|||
RE: HP Prime: CAS Commands in Home Mode
Hi,
To elaborate on the RPN syntax for calling CAS commands from HOME: 1. Simplify “simplify(4*atan(1/5)-atan(1/239))” [ENTER] CAS [ENTER] returns 1/4*pi 2. Expand a) If you use ‘X’ (uppercase): “expand(‘(X+3)^2’)” [ENTER] CAS [ENTER] returns X^2+6*X+9 b) if not: “expand((x+3)^2)” [ENTER] CAS [ENTER] returns x^2+6*x+9 3. Factor a) “factor(‘X^2-5*X+4’)” [ENTER] CAS [ENTER] returns (X-4)*(X-1) b) “factor(x^2-5*x+4)” [ENTER] CAS [ENTER] returns (x-4)*(x-1) 4. Differentiation “diff(‘COS(X)*SIN(X)’)” [ENTER] CAS [ENTER] returns -SIN(X)*SIN(X)+COS(X)*COS(X) “simplify(‘-SIN(X)*SIN(X)+COS(X)*COS(X)’)” [ENTER] CAS [ENTER] returns 2*COS(X)^2-1 5. Summation “sum(‘N^3’,’N’,1,9)” [ENTER] CAS [ENTER] returns 2025 6. Solving “zeros(‘X^3-6’)” [ENTER] CAS [ENTER] returns [1.81712059283] |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: