Proper way(s) to substitute X for x in a CAS expression
|
12-17-2013, 12:32 AM
Post: #1
|
|||
|
|||
Proper way(s) to substitute X for x in a CAS expression
Sometimes, its useful to take an expression (say x^2-5) from the CAS and plot it in Function app.
I know that its possible to substitute X for x in a CAS expression using the following f(x):= x^2-5 //which creates a CAS program f Function.F1:=f //which saves X^2-5 to F1 Are there any other straightforward ways of doing this? The subst() command does not seem to do it. Thanks |
|||
12-17-2013, 03:23 AM
Post: #2
|
|||
|
|||
RE: Proper way(s) to substitute X for x in a CAS expression
subst() does work for me.
e.g., subst(x^2-5,x='X') in CAS view returns the desired X^2-5. Then, store it in one of the predefined function names F1, etc. |
|||
12-17-2013, 05:15 PM
Post: #3
|
|||
|
|||
RE: Proper way(s) to substitute X for x in a CAS expression
(12-17-2013 03:23 AM)Helge Gabert Wrote: subst() does work for me. Thank you - yes I see where this substitutes X for x properly (I forgot the ' ' marks). Unfortunately, when storing this in Function.F1 using X^2-5 Sto> F1 or F1:=X^2-5 The expression is evaluated (using real X value) which results in a real value in F1, not the expression. The f(x):=expression then F1:f steps are not too onerous for now. |
|||
12-20-2013, 09:07 AM
Post: #4
|
|||
|
|||
RE: Proper way(s) to substitute X for x in a CAS expression
Hello,
Quote:Unfortunately, when storing this in Function.F1 using Yes, in the same way that you would expect A:=1+2 to result in A=3 and not 1+2... try using QUOTE (or '') as in: F1:='X²-5', it will work... QUOTE(input) (or 'input') stands for "do not evaluate what is inside" and is used just for that type of cases. Merry xmass! Cyrille |
|||
12-20-2013, 02:32 PM
Post: #5
|
|||
|
|||
RE: Proper way(s) to substitute X for x in a CAS expression
(12-20-2013 09:07 AM)cyrille de brébisson Wrote: try using QUOTE (or '') as in: Thank you. The above works as you show as long as CAS is in EXACT mode correct? It seems if it is in Approx mode then it still seems to evaluate 'X^2-5'. Happy holidays. |
|||
12-20-2013, 05:53 PM
(This post was last modified: 12-20-2013 05:55 PM by Han.)
Post: #6
|
|||
|
|||
RE: Proper way(s) to substitute X for x in a CAS expression
As much as I like the HP Prime, I must say that the way programs interact with the CAS at the moment feels a lot like "hacking" -- as in, there really isn't a straightforward way to do it and it looks like a bunch of tricks to get things to play nicely.
That said, a symbolic object on the HP Prime is surrounded by quotes. However, the Home view and CAS view treat symbolic objects differently as they have different parsing methods. For the time being, you must always assume that you are working in the Home view when you create any program. So one of the issues you will run into is the inability to use undefined variables in the Home view. This is why 'x^2-1' will produce an error (despite being an algebraic object) whereas as soon as you define lower case x, then the errors go away. The reason is because in the Home view, all objects can can be evaluated must return a real value when evaluated. So 'X^2-1' always works since capital X is always defined. So just how does one pass an expression so that it can be handled in CAS properly? For now, I would suggest strings. Use a combination of STRING(), EXPR(), and CAS() in addition to CAS.function() where possible. Below are some examples: Code:
The three examples above illustrate the following:
So, do what you need to do with strings, then pass the final result to the CAS() command. Here's an example of how to use symbolics inside a matrix: Code:
Convoluted, but if you study it carefully, it follows the scheme I outlined earlier. Now, to really muddy up the waters, certain CAS commands actually behave normally in the Home view (likely because their Home execution falls back on the CAS rules -.- *sigh*). In particular, the diff() command could be used with CAS.diff() or even just as diff() provided you use single quotes! But I'll save that for another day to discuss. (12-20-2013 02:32 PM)CR Haeger Wrote:(12-20-2013 09:07 AM)cyrille de brébisson Wrote: try using QUOTE (or '') as in: Specifically for built-in variables which take "formulas" for input, you can even get away with a string. For example: Code:
works just fine provided the string properly parses (i.e. if you were to type the formula in with double quotes, it must be a proper expression). Graph 3D | QPI | SolveSys |
|||
12-20-2013, 08:13 PM
Post: #7
|
|||
|
|||
RE: Proper way(s) to substitute X for x in a CAS expression
Thanks Han. Your post helped me to understand why I could not write prgm to do implicit differentiation on HP Prime. I didn't know about CAS and strings.
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)