mat2list command
02-17-2014, 09:11 PM
Post: #1
 Thomas Ritschel Member Posts: 66 Joined: Feb 2014
mat2list command
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
02-18-2014, 12:37 AM (This post was last modified: 02-18-2014 01:04 AM by massimo.)
Post: #2
 massimo Junior Member Posts: 21 Joined: Feb 2014
RE: mat2list command
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 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.

Massimo
from 34c to prime
02-18-2014, 08:01 AM
Post: #3
 parisse Senior Member Posts: 1,013 Joined: Dec 2013
RE: mat2list command
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.
02-18-2014, 06:57 PM
Post: #4
 Thomas Ritschel Member Posts: 66 Joined: Feb 2014
RE: mat2list command
(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...
02-19-2014, 07:38 AM
Post: #5
 parisse Senior Member Posts: 1,013 Joined: Dec 2013
RE: mat2list command
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> * )
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)