HP Forums
newbie question: how to take element from an array on command line - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: newbie question: how to take element from an array on command line (/thread-9789.html)



newbie question: how to take element from an array on command line - iamhuzhe - 12-27-2017 05:20 PM

say `iquorem(63, 23)` returns [2, 17], how do I get 2, or 17 out of that array[/quote]


RE: newbie question: how to take element from an array on command line - Arno K - 12-27-2017 06:10 PM

Perhaps with 'iquorem(63,23)[1]' or [2]
Arno


RE: newbie question: how to take element from an array on command line - salvomic - 12-27-2017 06:38 PM

(12-27-2017 06:10 PM)Arno K Wrote:  Perhaps with 'iquorem(63,23)[1]' or [2]
Arno

Using [1] (or [2]) is ok in CAS, however, and in Home it would perform an implicit multiplication...


RE: newbie question: how to take element from an array on command line - Terje Vallestad - 12-27-2017 07:16 PM

(12-27-2017 05:20 PM)iamhuzhe Wrote:  say `iquorem(63, 23)` returns [2, 17], how do I get 2, or 17 out of that array

Ans(1) should get you 2 and Ans(2) should get you 17 as one way (in CAS)

Cheers, Terje


RE: newbie question: how to take element from an array on command line - Arno K - 12-27-2017 08:57 PM

(12-27-2017 06:38 PM)salvomic Wrote:  
(12-27-2017 06:10 PM)Arno K Wrote:  Perhaps with 'iquorem(63,23)[1]' or [2]
Arno

Using [1] (or [2]) is ok in CAS, however, and in Home it would perform an implicit multiplication...

I totally forgot about that as I ususally always work in CAS. So here a solution is:
L1:=iquorem(63,23);
L1(1), recalls the first element of the result, that is 2
Arno


RE: newbie question: how to take element from an array on command line - salvomic - 12-27-2017 09:05 PM

(12-27-2017 08:57 PM)Arno K Wrote:  I totally forgot about that as I ususally always work in CAS. So here a solution is:
L1:=iquorem(63,23);
L1(1), recalls the first element of the result, that is 2
Arno

Right...
Maybe it is useful a more general way, that would be valid both in CAS and Home, to extract elements from matrices and vectors [].
i.e. in Home M1(2,3) is ok but [[1,2,3],[4,5,6],[7,8,9]] [2,3] tries to multiply, instead of extracting elements (in CAS that's ok).


RE: newbie question: how to take element from an array on command line - Rudi - 12-30-2017 08:20 PM

A possible solution:

a:=iquorem(63,23)
a(1)
a(2)

[attachment=5501]

Best Regards
Rudi