HP Forums
mat2list command - 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: mat2list command (/thread-701.html)



mat2list command - Thomas Ritschel - 02-17-2014 09:11 PM

I'm trying to convert a one-dimensional matrix (a vector) to a list.

The cataloque menu provides a function called "mat2list" which concatenates the rows of a matrix to just a single row. However, this is still a matrix object with square brackets, e.g. of type "4", which is not what I want (curly braces, type "6").
In contrast the oposite function "list2mat" works as expected.

Is there some other function for this purpose, or maybe some "type conversion"?

Thanks,
Thomas


RE: mat2list command - massimo - 02-18-2014 12:37 AM

Assign it to a "L" variable:

L3:=mat2list([[1,2],[3,4]])

Not very elegant, indeed.

Why not use some recursion in a CAS function?

lc(a):=PIECEWISE((length(a)) = 0,{},(length(a))>0,concat({head(a)},lc(tail(a))))

lc([a b c]) returns {a b c}

I like functional languages! BTW this is a classic example of tail recursion. Many functional languages translate it to a loop. It will be nice to know which is the CAS behavior.


RE: mat2list command - parisse - 02-18-2014 08:01 AM

Try convert(vector,23)
23 is the subtype of HP lists (Xcas does not make a difference between vectors and lists), 0 is for normal lists, 1 for sequences, 2 for sets.
And the CAS does not try to convert your code to a loop. It is interpreted like it was entered.


RE: mat2list command - Thomas Ritschel - 02-18-2014 06:57 PM

(02-18-2014 08:01 AM)parisse Wrote:  Try convert(vector,23)
23 is the subtype of HP lists (Xcas does not make a difference between vectors and lists), 0 is for normal lists, 1 for sequences, 2 for sets.

That's what I was looking for! Thanks!

It's just a bit confusing that CONVERT in Home view means Unit conversion. So one has to use CAS.convert instead...


RE: mat2list command - parisse - 02-19-2014 07:38 AM

I'm modifying mat2list to return a HP list.
The same CAS convert command performs list subtype conversion, unit conversion and also some rewriting commands (and in that case you can use STO> as a shortcut, like 1_m Sto> _cm or x^4-1 Sto> * )