Manipulating entries of Matrices

Questions and problems about using polymake go here.
ren
Posts: 38
Joined: 03 May 2011, 15:21

Manipulating entries of Matrices

Postby ren » 13 Nov 2016, 12:20

How do you access or change single entries of matrices?

For example, given the following polytope, I would like to construct the convex hull of its finite vertices and the origin:

Code: Select all

$q = new Polytope<Rational>(POINTS=>[[0,1,0],[0,0,1],[1,0,3],[1,1,1],[1,3,0]]);
My naive approach was to check which rows of $q->VERTICES have "1" as first entry, put them into a new matrix, add [1,0,0] to that matrix and construct a new polytope out of it.

edit: nevermind, you can access matrix elements using "->[j]" or "->elem(i,j)" and you change matrix elements using the latter.

User avatar
joswig
Main Author
Posts: 280
Joined: 24 Dec 2010, 11:10

Re: Manipulating entries of Matrices

Postby joswig » 14 Nov 2016, 10:21

Yes, this is how you can make such changes. Yet, please, pay attention to the following example.

The first variant gives an error

Code: Select all

> $interval=new Polytope(POINTS=>[[1,0],[1,1]]); > $p=$interval->POINTS; > $p->elem(1,1)=2; polymake: ERROR: Attempt to modify a read-only C++ object at input line 1.
whereas the following

Code: Select all

> $q=new Matrix($interval->POINTS); > $q->elem(1,1)=2;
is OK.


Return to “Helpdesk”