HP Forums

Full Version: newbie question: how to take element from an array on command line
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
say `iquorem(63, 23)` returns [2, 17], how do I get 2, or 17 out of that array[/quote]
Perhaps with 'iquorem(63,23)[1]' or [2]
Arno
(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...
(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
(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
(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).
A possible solution:

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

[attachment=5501]

Best Regards
Rudi
Reference URL's