solve() problems
06-04-2021, 07:51 PM
Post: #1
 HansB Junior Member Posts: 8 Joined: May 2021
solve() problems
Hello, I am new to Prime, and new to this forum, so please forgive my ignorance!
I am trying to learn about equations and HP Prime's possibilities in solving equations. Now on my Home screen using solve() function does not give me any solutions, just X. For instance taking the simple example from the solve() Help:
solve(X-3=1) -> X
Same happens with all other equations.
What is going on?

I am using Textbook entry method.
Software version 2021/05/05. Hardware version D. OS V2.060.650
06-05-2021, 06:17 AM
Post: #2
 rawi Member Posts: 106 Joined: Nov 2019
RE: solve() problems
You have to tell the calculator for what variable you want to solve.
So if you put in solve(x-3=1,x) you get the right answer {4}.

Best

Raimund
06-05-2021, 07:06 AM
Post: #3
 Joe Horn Senior Member Posts: 1,859 Joined: Dec 2013
RE: solve() problems
(06-04-2021 07:51 PM)HansB Wrote:  ... Now on my Home screen using solve() function does not give me any solutions, just X. For instance taking the simple example from the solve() Help:
solve(X-3=1) -> X

Two problems here. (1) Home view is intended for floating-point number crunching, not symbolic math manipulations or exact calculations. That's what CAS view is for. (2) Notice that all the examples for solve() in the Help system use lowercase 'x', which causes a syntax error in Home view when no value has been stored in the variable 'x' yet. This serves as a reminder to you that solve() is a function that performs symbolic math manipulation, so you should only use it in CAS, where undeclared variables are treated symbolically as expected, instead of as syntax errors.

You can force Home to treat uppercase 'X' as a symbolic variable (which it isn't really) by putting your algebraic expressions in single quote marks like this:
solve( 'X^2-3=1' , 'X' )
but that's silly. Use CAS for CAS problems, and use Home for number crunching.

<0|ɸ|0>
-Joe-
06-05-2021, 07:19 AM
Post: #4
 HansB Junior Member Posts: 8 Joined: May 2021
RE: solve() problems
(06-05-2021 06:17 AM)rawi Wrote:  You have to tell the calculator for what variable you want to solve.
So if you put in solve(x-3=1,x) you get the right answer {4}.
Thank you, but this is not happening for me.
If I input solve(x-3=1,x), with lower-case x, I get a Syntax Error.
If I input solve(X-3=1,X), with upper-case X, I get {X}, not {4}.
The same happens without specifically giving the Var.
Help says one syntax is: solve(Expr,[Var]), so Var should be optional, and there is no dis-ambiguity about which var should be solved.

Actually the same happens on the HP Prime Lite app I just installed on my Android phone.

Apart from solve() function apparently not working, I find the Help examples misleading, because using one as written gives a Syntax Error (due to the lower-case x in the example), and confusing, because use of a small superscript 2, which the x^2 key does not deliver.
06-05-2021, 07:28 AM
Post: #5
 HansB Junior Member Posts: 8 Joined: May 2021
RE: solve() problems
(06-05-2021 07:06 AM)Joe Horn Wrote:
(06-04-2021 07:51 PM)HansB Wrote:  ... Now on my Home screen using solve() function does not give me any solutions, just X. For instance taking the simple example from the solve() Help:
solve(X-3=1) -> X

Two problems here. (1) Home view is intended for floating-point number crunching, not symbolic math manipulations or exact calculations. That's what CAS view is for. (2) Notice that all the examples for solve() in the Help system use lowercase 'x', which causes a syntax error in Home view when no value has been stored in the variable 'x' yet. This serves as a reminder to you that solve() is a function that performs symbolic math manipulation, so you should only use it in CAS, where undeclared variables are treated symbolically as expected, instead of as syntax errors.

You can force Home to treat uppercase 'X' as a symbolic variable (which it isn't really) by putting your algebraic expressions in single quote marks like this:
solve( 'X^2-3=1' , 'X' )
but that's silly. Use CAS for CAS problems, and use Home for number crunching.
Ah, thank you! That is very helpful and solves my confusions! A real beginner's error!
06-05-2021, 07:43 AM (This post was last modified: 06-05-2021 08:04 AM by C.Ret.)
Post: #6
 C.Ret Member Posts: 190 Joined: Dec 2013
RE: solve() problems
@rawi:
No, you don't have to indicate the variable to be search for when you use default x variable. It is mandatory only in case of several variables in the equation.

@HansB
I think the problem come from a confusion between the symbolic CAS variable x (lowercase) and the global variable X (uppercase). In the CAS windows, the later X is consider as a numeric constant.

In CAS mode, if you indicate to solve over global register X (uppercase) in solve, expected answer is display what ever the value store in X.

If you don't indicate variable to solve, default symbolic CAS variable x (lowercase) is used and the equation containing the X register is first numerically evaluated.

When X is not storing value 4, solve returns empty solution set [ ] since no symbolic x will ever made X-3 to be 1.
When X is storing the correct value 4, solve returns the infinite symbolic solution set { x } (lowercase) to indicate that any values of x will fit, since, whatever is x, (4-3) always eval to 1.

Concerning solve behavior in HOME, I have no explanation.

@Joe Horn
Sorry my post crossed yours. You are perfectly right when stating that solve is not intended to be used in HOME numeric environment.

The main goal of solve is symbolic solving and dependencies resolving:

06-05-2021, 09:53 AM
Post: #7
 toml_12953 Senior Member Posts: 1,904 Joined: Dec 2013
RE: solve() problems
(06-04-2021 07:51 PM)HansB Wrote:  Hello, I am new to Prime, and new to this forum, so please forgive my ignorance!
I am trying to learn about equations and HP Prime's possibilities in solving equations. Now on my Home screen using solve() function does not give me any solutions, just X. For instance taking the simple example from the solve() Help:
solve(X-3=1) -> X
Same happens with all other equations.
What is going on?

I am using Textbook entry method.
Software version 2021/05/05. Hardware version D. OS V2.060.650

solve() is meant to be run in CAS mode which is why it's in lowercase. In general, when you see a lowercase command or function, run it in CAS mode.

Tom L
Cui bono?
06-05-2021, 06:29 PM
Post: #8
 Dougggg Member Posts: 102 Joined: Dec 2013
RE: solve() problems
This worked for me in home mode:
Solve.SOLVE(X-3=1,X)
06-05-2021, 07:25 PM (This post was last modified: 06-05-2021 07:26 PM by C.Ret.)
Post: #9
 C.Ret Member Posts: 190 Joined: Dec 2013
RE: solve() problems
Yes, that's the SOLVE function from the Solve Application.

Using the Solve application is a useful feature where you can save equations and user variables you are using daily for your specific usage. Very conveniant.
06-06-2021, 08:42 AM (This post was last modified: 06-06-2021 08:58 AM by HansB.)
Post: #10
 HansB Junior Member Posts: 8 Joined: May 2021
RE: solve() problems
Thanks for all the good advise!

If I investigate polynomials in the Function app, the Symb view uses and demands a upper-case X in the expressions. The Plot view gives the functions as nice plots, and I can even get numerical solutions for Root through soft keys Menu -> Fcn, but only one at a time, and I need to trace via cursor keys to get other solutions.

But in symb view I can copy a function, and paste it into Home screen, and there use solve(''), for instance solve('X^2 +X-1'), which gives me the numerical Root solutions. solve() assumed I wanted the roots, i.e. X^2 +X-1=0. But if I paste the function into CAS and use solve(), I get a syntax error, and have to change the case of all X from upper to lower. Then it works, with a warning that it is not an equation, and assumes it to be =0. And then I get the exact algebraic root solutions to the polynomial function. This is great too, but it is a much more cumbersome process, having to edit each function pasted, to convert all upper case X to lower case x! The CAS mode seems the more logical way to do such investigations, but it does not communicate too well with Symb view in Function app, it seems, or rather vice versa. All because of X <-> x differences.

It would be cool in Function Plot view to get solutions to Root etc not only numerical, but, at a press of a soft button, also algebraic. Another quibble I got with the Function app is this: investigating a function in Plot view and tracing it and for instance finding a Root via the soft menu, the tracer is put onto the solution, the solution is given numerically, but if I then jump to another graphed function via up/down cursor keys, the trace cursor is not at precisely the same X anymore, so the F(X) values are not quite comparable. It would be nice if they were!
06-06-2021, 02:45 PM (This post was last modified: 06-06-2021 03:37 PM by C.Ret.)
Post: #11
 C.Ret Member Posts: 190 Joined: Dec 2013
RE: solve() problems
If you need only a rapid aperçu of the plot of your polynomial, you may use plotfunc(x²+x-1). You can easily have it full screen; touch the small plot figure and tap the (show) menu at the bottom of the screen.

If your polynomial expression is short enough, you can retape it into the Function App edit window.
But, if you are as lazy as me, an élégante solution consist in firth selecting the Function Application, then create a new program named CAS2FUN as a CAS function (don't forget to mark the case).

Code:
EXPORT CAS2FCN(Epr)                          // Returns CAS expression with lowercase x substituate by uppercase X BEGIN  EXPR( REPLACE("'"+STRING(Epr)+"'","x","X")) END; EXPORT CAS2FCN(Epr,n)                                 // Store substituated CAS expression as a regular plot function in slot Fn BEGIN  EVAL(EXPR(" ' F"+n+":= ' "+STRING(CAS2FCN(Epr))+" ' ' "));  CHECK(n);  n END;
(Beware the position of single quote ' and double quote " Sehr wichtig !)

In the CAS window, you can copy any sophisticate exression as easily as the simplest by using this new CAS program :
Press [ToolBox]
Touch (USER) and select CAS2FUN in the list of User's program
Then select your polynomial expression in the display stack and touch (COPY) in the menu. This enter the expression of it as first argument of CAS2FUN
Then enter a number to designate the Function Application slot number to be used (from 1 to 9 or 0) and press [ENTER].

The program convert your sophisticated expression by replacing lowercase x with uppercase X without evaluating it and store it in the F1 ... F0 slot of you chose ready to be plot !

La cerise sur la gâteau , you now have named your polynomials F1(x) and F2(x): so you can use these names to designate your polynomials to integrate, derivate or solve (or what ever you plan to do with these)
For example, in CAS windows: solve(F1(x)=F2(x),x) will return the list of the abscisses for all of the intersections : { -1.9308, 0.837,3.0938}
06-06-2021, 03:54 PM
Post: #12
 Albert Chan Senior Member Posts: 1,913 Joined: Jul 2018
RE: solve() problems
Hi, HansB

You can quote the expression in CAS, to keep variable X "symbolic"

CAS> solve('X*X+X-1'=0, X) ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ → {1/2*(-√5-1), 1/2*(√5-1)}
CAS> proot('X*X+X-1') ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ → [−1.61803398875, 0.61803398875]
06-07-2021, 12:53 PM (This post was last modified: 06-07-2021 12:56 PM by HansB.)
Post: #13
 HansB Junior Member Posts: 8 Joined: May 2021
RE: solve() problems
(06-06-2021 03:54 PM)Albert Chan Wrote:  You can quote the expression in CAS, to keep variable X "symbolic"

CAS> solve('X*X+X-1'=0, X) ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ → {1/2*(-√5-1), 1/2*(√5-1)}
CAS> proot('X*X+X-1') ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ → [−1.61803398875, 0.61803398875]
Thank you, works nicely! So solve() with expression in single quotes is quite useful, both in Home and in CAS, only CAS needs explicit mention of which var to solve, and never mind it is in upper case!

C.Ret Wrote:[....]
The program convert your sophisticated expression by replacing lowercase x with uppercase X without evaluating it and store it in the F1 ... F0 slot of you chose ready to be plot !
[....]
Thank you, your CAS2FUN program works beautiful, especially as it can place the expression into a Fn var of Function, and it gets instantly plotted there!

How do I write a reverse function, say FUN2CAS(n), which takes Fn from Function and inserts it into the CAS, with upper X replaced by lower x?
06-07-2021, 06:09 PM (This post was last modified: 06-07-2021 06:11 PM by C.Ret.)
Post: #14
 C.Ret Member Posts: 190 Joined: Dec 2013
RE: solve() problems
The good new is you don't need to program any reverse functionality:

The name of the slot F1 F2 ... F9 F0 are global , you can directly use they with CAS variables : F1(x) returns the initial expression !

All CAS functions and Twix are available.

06-08-2021, 06:34 AM (This post was last modified: 06-08-2021 10:59 AM by HansB.)
Post: #15
 HansB Junior Member Posts: 8 Joined: May 2021
RE: solve() problems
(06-07-2021 06:09 PM)C.Ret Wrote:  The good new is you don't need to program any reverse functionality:

The name of the slot F1 F2 ... F9 F0 are global , you can directly use they with CAS variables : F1(x) returns the initial expression !

All CAS functions and Twix are available.
Ahh, thank you! The small x again! solve(F1(x)) etc works great in CAS, but F1 imports the expression rather differently than F1(x), and F1(X) throws an error. Then in CAS the case of the alpha keys works opposite to that in Home, and opposite to what is written on the keys. All this needs getting used to by me, I need to watch the character case indicator top left like a hawk...

PS: I do find it a pity and somewhat a design flaw, that one cannot simply do in CAS for instance x^2-sqrt5+1—>F3 (but as textbook entry). Perhaps the Function app should have a modus for lower case x. Using your custom function CAS2FUN does not quite solve the problems, since an expression gets evaluated, like sqrt5 will be transformed into its numerical approximation.
06-09-2021, 08:53 PM
Post: #16
 C.Ret Member Posts: 190 Joined: Dec 2013
RE: solve() problems
HI,

I am disappointed by the fact that my CAS2FUN program convert square root into numeric. This is not an expected feature. Maybe a bug I have to report to Cyril and his team in relation with the beta version having the new '"Intelligent math" feature ?

By luck, using double quote, the exact expression maybe introduce into Fn Plot Function Slot :

07-13-2021, 07:04 PM
Post: #17
 Albert Chan Senior Member Posts: 1,913 Joined: Jul 2018
RE: solve() problems
Hi, C.Ret

You may not need the function CAS2FUN.

CAS> F1(z) := z^2 - √5 + 1

(X) -> X^2 - (√5) + 1
07-14-2021, 08:19 AM (This post was last modified: 07-14-2021 08:22 AM by C.Ret.)
Post: #18
 C.Ret Member Posts: 190 Joined: Dec 2013
RE: solve() problems
(07-13-2021 07:04 PM)Albert Chan Wrote:  You may not need the function CAS2FUN.

CAS> F1(z) := z^2 - √5 + 1

(X) -> X^2 - (√5) + 1

Yes, thanks a lot ! I just unexpectedly discover that fact yesterday evenig by accident when playing with GLOBAL, cas and user's variables due to your inputs in this thread.

Today, I was just finishing a message to indicate that CAS2FUN is completely useless, when I discover you see it before me !

That a nice feature, and we don't have to worry about the radical or other approximate values that may alter the format of the plotted functions any more

Cool day !
08-06-2021, 08:39 PM
Post: #19
 jte Member Posts: 165 Joined: Feb 2014
RE: solve() problems
(06-06-2021 08:42 AM)HansB Wrote:  ... Another quibble I got with the Function app is this: investigating a function in Plot view and tracing it and for instance finding a Root via the soft menu, the tracer is put onto the solution, the solution is given numerically, but if I then jump to another graphed function via up/down cursor keys, the trace cursor is not at precisely the same X anymore, so the F(X) values are not quite comparable. It would be nice if they were!

One workaround with the current UI is to use the Plot-Table view. If, after jumping to a root via Fcn / Root, one presses Up or Down, the X coordinate will not be changed (unlike in the standard Plot view).

When I implemented the Function app for the 39gII, the UI specification for the 39gII's Function app was for it to match the UI of the 39gs's Function app. (The Prime's Function app implementation is derived from the 39gII's; one started where the other left off. I didn't reference any of the source for the 39gs when implementing the Function app for the 39gII, but tried to be quite observant as to the details of the 39gs as I went along... which is why I remember some UI details.) Some of these UI details should undoubtedly be reviewed; I have a suspicion that some aspects of the 39gs's UI were driven by computational efficiency concerns.
08-06-2021, 09:25 PM (This post was last modified: 08-06-2021 09:34 PM by Liamtoh Resu.)
Post: #20
 Liamtoh Resu Member Posts: 113 Joined: May 2021
RE: solve() problems
Quote from HansB

Quote:PS: I do find it a pity and somewhat a design flaw, that one cannot simply do in CAS for instance x^2-sqrt5+1—>F3 (but as textbook entry). Perhaps the Function app should have a modus for lower case x. Using your custom function CAS2FUN does not quite solve the problems, since an expression gets evaluated, like sqrt5 will be transformed into its numerical approximation.

From the CAS environment, I did this:

csolve(x^2-sqrt5+1=0)

and the Prime returned two complex answers.

edit: Sorry, I did "csolve(x^2+sqrt5+1=0)" instead of "csolve(x^2-sqrt5+1=0)"
The Prime produced plus or minus (sqrt(sqrt(5)-1)).

Later.
 « Next Oldest | Next Newest »

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