HP Forums

Full Version: Vector or list to Number "conversion" (SOLVED.)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Hi Guys!
I'm trying to compare the numeric value of two objects, one is a vector with only one numeric value and the other is a real number; [1/2]==0.5 the Hp Prime returns a zero.

I searched
this forum and the UG. for a command that takes the [1/2] out of the brackets so I can compare them, but I found nothing.

this vector [1/2] is the result of solving an equation using the SOLVE command.

what can I do to make the caparison a true statement?

Thank you.
If I define

result:=[1/2]

and do result(1)==0.5 it works on my emulator. You can access a list or vector by round brackets. First element index 1.
Hello,

Are you in CAS or Home?

In home, assuming that your vector is stored in a variable (vec for example), doing EVAL(vec(1))==0.5 will do the trick.

Cyrille
Perhaps a "List" approach might be useful?

mat2list([1/2]) == 1/2 => {1}

mat2list([1/2, 1/4, 1/2]} == 1/2 => {1, 0, 1}

Using the list facility the test applies to one (or more) elements, without referencing a specific element number.

-Dale-
(03-20-2015 03:38 AM)Spybot Wrote: [ -> ][size=large]
Hi Guys!
I'm trying to compare the numeric value of two objects, one is a vector with only one numeric value and the other is a real number; [1/2]==0.5 the Hp Prime returns a zero.
...

(03-20-2015 09:46 AM)Angus Wrote: [ -> ]If I define

result:=[1/2]

and do result(1)==0.5 it works on my emulator. You can access a list or vector by round brackets. First element index 1.

rigorously speaking, a vector with only one component is always a vector, non a real...
So, TYPE([½])= 4 (matrix or vector), and type([½]) = DOM_LIST, and in fact is also a list)

You must use [½](1) to get a value 0.5, and then
type([½](1)) = DOM_RAT and TYPE(...) = 0, a real

I hope this could help you.

Salvo
All You Guys provided Great solutions!

PROBLEM SOLVE!!!

Thank you Guys!
Reference URL's