atan2() Storing symbolic expression into numeric only vector object *Error*
|
09-03-2018, 10:06 PM
(This post was last modified: 09-04-2018 12:52 AM by Magnus512.)
Post: #1
|
|||
|
|||
atan2() Storing symbolic expression into numeric only vector object *Error*
Hi there, I'm making my own program to change between coordinate systems:
------------- EXPORT SPHERE; //Rectangular to Spherical //(x,y,z)-->(ρ,θ,φ) EXPORT RECT2SPHE(CORD) BEGIN //Separacion de coordenadas en x,y y z. LOCAL x:=CORD(1),y:=CORD(2),z:=CORD(3); //Variables para guardar resultado temporal LOCAL ρ:=0,θ:=0,φ:=0; //Operaciones para convertir los valores ρ:=SQRT((x)^2+(y)^2+(z)^2); θ:=atan(y/x); φ:=ACOS(z/ρ); //Guardar el resultado en la variable global SPHERE SPHERE:=[ρ,θ,φ]; RETURN("ρ="+ρ+" θ="+θ+" φ="+φ); END; --------------------------- This is a part of the code, but I have some torubles here, when I store the results into SPHERE variable using atan to get the angle (θ:=atan(y/x)) it works just perfect, but if I try to use atan2(y,x) I get this message The error comes out when I use radian mode, but it works in degrees. |
|||
09-03-2018, 11:46 PM
Post: #2
|
|||
|
|||
RE: atan2() Storing value into a vector *Error*
Is atan2(x,y) implemented by HP Prime? I can't see it in the catalog.
— Ian Abbott |
|||
09-04-2018, 12:10 AM
Post: #3
|
|||
|
|||
RE: atan2() Storing value into a vector *Error* | |||
09-04-2018, 12:28 AM
(This post was last modified: 09-04-2018 12:38 AM by Tim Wessman.)
Post: #4
|
|||
|
|||
RE: atan2() Storing value into a vector *Error*
Apparently it is.... looks like the CAS author added it in his parser at rev 13787.
Wouldn't you need to separate your argument into 2 inputs? When I do that and run the debugger on your progam, I discover that you get back a symbolic object of 'ATAN(...)' which isn't a valid input into a vector. You need to evaluate that to a number. Put EVAL( ) around your atan2 call. TW Although I work for HP, the views and opinions I post here are my own. |
|||
09-04-2018, 12:30 AM
(This post was last modified: 09-04-2018 12:36 AM by Albert Chan.)
Post: #5
|
|||
|
|||
RE: atan2() Storing value into a vector *Error*
(09-04-2018 12:10 AM)Magnus512 Wrote:(09-03-2018 11:46 PM)ijabbott Wrote: Is atan2(x,y) implemented by HP Prime? I can't see it in the catalog. Should it be atan2(y, x) ? Quote:The error comes out when I use radian mode, but it works in degrees. Does the undocumented atan2() work in radian mode ? |
|||
09-04-2018, 12:33 AM
Post: #6
|
|||
|
|||
RE: atan2() Storing value into a vector *Error* | |||
09-04-2018, 12:35 AM
Post: #7
|
|||
|
|||
RE: atan2() Storing value into a vector *Error*
(09-04-2018 12:30 AM)Albert Chan Wrote:(09-04-2018 12:10 AM)Magnus512 Wrote: Is not there, but it is implemented, try it When I use atan2(y,x)... in radian it works, but when I implement it in a function and try to "concatenate" in to a vector with the other two answers it doesn't work, again this is just in radian mode, no degree mode problem |
|||
09-04-2018, 12:39 AM
(This post was last modified: 09-04-2018 12:41 AM by Tim Wessman.)
Post: #8
|
|||
|
|||
RE: atan2() Storing value into a vector *Error*
Like I mentioned, run the debugger and you'll see the problem on the first pass...
A better title for this thread should actually be "atan2() Storing symbolic expression into numeric only vector object *Error*" TW Although I work for HP, the views and opinions I post here are my own. |
|||
09-04-2018, 12:48 AM
(This post was last modified: 09-04-2018 12:51 AM by Magnus512.)
Post: #9
|
|||
|
|||
RE: atan2() Storing value into a vector *Error*
(09-04-2018 12:39 AM)Tim Wessman Wrote: Like I mentioned, run the debugger and you'll see the problem on the first pass... I ran the debugger but everything looks just fine until the storing point , and yes the first result of atan2() is amm "exact" I don't think symbolic... so maybe if a pass it to eval comand ... and I found this and seems to work http://www.hpmuseum.org/forum/archive/in...-3604.html |
|||
09-04-2018, 12:54 AM
(This post was last modified: 09-04-2018 12:56 AM by Magnus512.)
Post: #10
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error*
Parsing atan2(y,x) into EVAL() did the trick. . If I remeber well, this error is just with vectors a list works well
|
|||
09-04-2018, 01:48 AM
Post: #11
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error*
(09-04-2018 12:54 AM)Magnus512 Wrote: Parsing atan2(y,x) into EVAL() did the trick. . If I remeber well, this error is just with vectors a list works well I am not so sure. I think atan2(y,x) has an object reference count bug. This is my guess ... It fail inside RECT2SPHE (radian mode) because local variable is gone after leaving function. (Object reference count drop to 0, object thus becomes "garbage") It work with degrees because atan2 value multiply by factor, creating a new object. EVAL work for the same reason (new object). If true, it will fail with list too. Try it without EVAL, and RECT2SPHE return list instead. |
|||
09-04-2018, 02:43 AM
Post: #12
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error*
(09-04-2018 01:48 AM)Albert Chan Wrote:Here it is, without EVAL(), usign atan(y,x), and returning a list(09-04-2018 12:54 AM)Magnus512 Wrote: Parsing atan2(y,x) into EVAL() did the trick. . If I remeber well, this error is just with vectors a list works well |
|||
09-04-2018, 05:56 AM
Post: #13
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error*
atan2 was added for Python compatibility, it uses the same convention as Python or the standard libc for the arguments.
|
|||
09-04-2018, 10:54 AM
Post: #14
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error* | |||
09-04-2018, 11:40 AM
Post: #15
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error*
Yes, it does. The reason why is that exact values, or fractions will result in exact symbolic results being returned from the CAS command atan2 Then when that local varaible is used in the vector, it errors.
Approxate decimals will work for non integer, but the only way to be sure is to eval or approximate that value. TW Although I work for HP, the views and opinions I post here are my own. |
|||
09-04-2018, 12:32 PM
Post: #16
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error*
(09-04-2018 11:40 AM)Tim Wessman Wrote: Yes, it does. The reason why is that exact values, or fractions will result in exact symbolic results being returned from the CAS command atan2 Then when that local varaible is used in the vector, it errors. So any chance to get this working, without the EVAL() command?... Is this a bug, or it's the normal behavior of system working with vectors? |
|||
09-04-2018, 12:52 PM
Post: #17
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error*
Hi, Magnus512
I still think atan2(3, 2) not honors approx. mode is a bug. It should be able to substitute directly for atan(3/2), but better (correct angle for others quadrants) Can you try remove EVAL, but set θ:=atan2(y, x) + 0 ? Unless Prime can optimize away + 0, it should force atan2 to honor exact/approx mode. |
|||
09-04-2018, 03:17 PM
Post: #18
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error*
The documented function ARG(x+y*i), returns the angle in the correct quadrant.
ARG((-2,-1)) -> -2.67... (radiant mode) ARG((-2,-1)) -> -153.43... (degree mode) Josep Mollera. HP PRIME, HW: C, SW: 2.2.15157 (2024-09-01). |
|||
09-04-2018, 04:20 PM
Post: #19
|
|||
|
|||
RE: atan2() Storing symbolic expression into numeric only vector object *Error*
(09-04-2018 03:17 PM)JMB Wrote: The documented function ARG(x+y*i), returns the angle in the correct quadrant. This is good, and I have notice this yet, but the focus point is the behavior of the vector, why we can't store and aprox. result there. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)