Post Reply 
nSolve
02-01-2014, 08:30 PM
Post: #1
nSolve
Ok, I admit this might be a silly question but the syntax of the nSolve function in the CAS View is a bit tricky.

On page 331 of of the HP Prime User Guide (Edition 1, July 2013) you can find this example:
Quote:nSolve(cos(x)=x,x=1.3) gives 0.739085133215

When I enter this on the HP Prime I get this message:
Quote:"nSolve(cos(x)=x,x=1.3) Error: Bad Argument Value"

Now I enter the same expression with quotes:
Quote:nSolve('cos(x)=x','x=1.3')

then I get the expected result:
Quote:0.739085133215

Do I miss something or are the quotes missing in the user guide? Or do I have to change the settings?

Many thanks.

Domink
Find all posts by this user
Quote this message in a reply
02-01-2014, 08:46 PM
Post: #2
RE: nSolve
The Home view is different from CAS view. That's really the only thing you need to watch out for. In Home view, all variables (or anything being parsed that might be treated as a variable) must be defined. By quoting as you did, the arguments are un-evaluated. You can also use double quotes, as well. These are a little easier to manage than single-quoted objects.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-01-2014, 09:03 PM
Post: #3
RE: nSolve
(02-01-2014 08:46 PM)Han Wrote:  The Home view is different from CAS view. (...)

Han,
Many thanks for your quick reply.
The problem I am describing above appears in the CAS view.

I get this message when I use double quotes instead of single quotes:
Quote:"nSolve(""cos(x)=x"",""x=1.3"",3) Error: Bad Argument Value"

Dominik
Find all posts by this user
Quote this message in a reply
02-01-2014, 09:29 PM
Post: #4
RE: nSolve
It appears I was a bit presumptuous -- I thought you were trying to use this command from the Home view (this is where single or double quotes would be necessary).

From home view, I typed: nSolve("cos(x)=x","x=1.3") and it works fine.
From CAS view, I typed: nSolve(cos(x)=x,x=1.3) and this work as well.

You are saying that in CAS view, typing nSolve(cos(x)=x,x=1.3) produces an error? Perhaps you have x already defined? To test, type x all by itself (lowercase) and see if it returns a real number (as opposed to just the variable itself). If so, then use purge(x) to delete the CAS variable. Most commands will balk at the use of a variable that has also been defined.

To add more complexity to the situation, storing a value into x in the Home view creates an x variable distinct from one created in the CAS view!

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-01-2014, 09:49 PM (This post was last modified: 02-01-2014 09:51 PM by Dominik Holenstein.)
Post: #5
RE: nSolve
(02-01-2014 09:29 PM)Han Wrote:  You are saying that in CAS view, typing nSolve(cos(x)=x,x=1.3) produces an error? Perhaps you have x already defined? To test, type x all by itself (lowercase) and see if it returns a real number (as opposed to just the variable itself). If so, then use purge(x) to delete the CAS variable. Most commands will balk at the use of a variable that has also been defined.

To add more complexity to the situation, storing a value into x in the Home view creates an x variable distinct from one created in the CAS view!

Han,

Direct hit!
Yes, I have x already defined. After using purge(x) the expression worked as printed in the user guide without single quotes.

I get a different result egarding storing a value into x in the Home view.

My steps:

1) Delete all variables x (either CAS Vars or User Variables)
2) Switch to Home view
3) Set the entry format to Algebraic
3) 8 [Sto>] x
4) Switch to CAS view
5) x [Enter]
6) 8.
7) Still in CAS view:
8) 10 [Sto>] x
9) x [Enter]
10) 10.
11) Switch to Home View
12) x [Enter]
13) 10

So I can change x either in CAS or in the Home view an it seems there is only one x variable in the System.

Check:
[Shift] [Suitcase] -> User Variables -> there is a user variable x with the value 10 and no variable x under CAS Vars.

Apart from this complexity: Many thanks for your help, it is much appreciated.

Dominik
Find all posts by this user
Quote this message in a reply
02-01-2014, 11:51 PM (This post was last modified: 02-01-2014 11:55 PM by Han.)
Post: #6
RE: nSolve
(02-01-2014 09:49 PM)Dominik Holenstein Wrote:  Check:
[Shift] [Suitcase] -> User Variables -> there is a user variable x with the value 10 and no variable x under CAS Vars.

Apart from this complexity: Many thanks for your help, it is much appreciated.

Dominik

If you create it under CAS first, though, then it will not show up in the memory browser under user variables. Instead, it is considered a CAS variable. My wording could have been better. I don't mean you can create two instances of 'x' but that there is a difference between where you create the variable (Home vs CAS). When you create it in CAS, you can purge() it but this is not true if created in Home.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 




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