Post Reply 
How do I correctly use the SOLVE() function in Python?
09-17-2023, 07:49 AM
Post: #1
How do I correctly use the SOLVE() function in Python?
I am increasingly committed to using HP Prime's Python as the main programming language at the university. However, I still stumble on simple things, like using the solve() function, which on PC Python I can easily use by importing the sympy library. However, on the HP prime I am limited to the functions and libraries that already come with it, which are many. And what I'm most interested in knowing how to use is the SOLVE() function, however I'm having difficulty introducing the Var argument? because every time I enter it, it informs me that I did not declare the 'x'. How to resolve this? Follow my code.

#python export test3()
import linalg

conta = eval("2*x+8")
x = eval("x")
print(linalg.solve(conta,x))

#end


Attached File(s) Thumbnail(s)
       
Find all posts by this user
Quote this message in a reply
09-17-2023, 03:24 PM
Post: #2
RE: How do I correctly use the SOLVE() function in Python?
The CAS library is named cas, not linalg (which is for linear algebra).
Code:

from cas import *
caseval("solve(2x+8=0,x)")
caseval (or xcas) takes a string as argument and returns a string. It can also take a string containing the commandname, and several arguments (maximum 7). These arguments will be printed to a string (unless they are already strings) and appended to the commandname string with "(" and "," and ")" added. Example:
Code:

from cas import *
x="x"
xcas("solve","2x+8=0",x)
Find all posts by this user
Quote this message in a reply
10-16-2023, 05:20 PM
Post: #3
RE: How do I correctly use the SOLVE() function in Python?
Sorry to hijack this thread, how can I find all the supported python modules on the HP Prime, like linalg or cas seen in this thread?

Where are they documented (like a list and their content, how to use them...)

My calculator collection
Find all posts by this user
Quote this message in a reply
10-16-2023, 06:22 PM
Post: #4
RE: How do I correctly use the SOLVE() function in Python?
(10-16-2023 05:20 PM)adumont Wrote:  Sorry to hijack this thread, how can I find all the supported python modules on the HP Prime, like linalg or cas seen in this thread?

Where are they documented (like a list and their content, how to use them...)

Once the Python app is active push either <Symb> for the editor or <Num> for the command line.
Then touch <Cmds> and the list of available modules open. There you can navigate through the various modules and their functions. Sometimes even a useful help text is available.

Günter
Find all posts by this user
Quote this message in a reply
10-17-2023, 11:34 AM
Post: #5
RE: How do I correctly use the SOLVE() function in Python?
Another member has captured a list here.

I don't know of any official documentation of all the functionality. The documentation on the calculator (Help) is brief and/or incomplete unfortunately.

(10-16-2023 05:20 PM)adumont Wrote:  Sorry to hijack this thread, how can I find all the supported python modules on the HP Prime, like linalg or cas seen in this thread?

Where are they documented (like a list and their content, how to use them...)

Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 4 Guest(s)