Karim Belabas on Sun, 30 Mar 2014 09:48:41 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Unidentified subject! |
* Giacomo Mulas [2014-03-30 09:06]: > On Fri, 28 Mar 2014, Bill Allombert wrote: > > >But your code is doing > > gmael2(coeffs2,2,4) = stoi(2); > >so it is modifying the older columns. > > > >maybe you wanted to do > > gmael2(coeffs2,4,2) = stoi(2); > >in which case you would be correct. > > oops, I had assumed that the first index would be the row and the second the > column, so I thought that gmael2(coeffs2,2,4) meant "second row, fourth > column". I am now learning from you that it's the reverse, if I understand > what you mean. This would explain things, indeed. mael means "Multi-dimensional Array ELement": gmael(x,2,4) fetches/assigns data corresponding to x[2][4]; more generally, gmael<n>(x,i1,i2,...,in) is associated to x[i1][i2]...[in]. To consider x as a matrix and fetch x[i,j] as you expected, use gcoeff(x,i,j). To avoid difficulties, you can use the following to build an mxn matrix, one column at a time: GEN m = cgetg(n+1,t_MAT); for (j = 1; j <= n; j++ { GEN c; gel(m, j) = c = cgetg(m+1,t_COL); for (i = 1; i <= m; i++) gel(c,i) = ...; } Cheers, K.B. -- Karim Belabas, IMB (UMR 5251) Tel: (+33) (0)5 40 00 26 17 Universite Bordeaux 1 Fax: (+33) (0)5 40 00 69 50 351, cours de la Liberation http://www.math.u-bordeaux1.fr/~kbelabas/ F-33405 Talence (France) http://pari.math.u-bordeaux1.fr/ [PARI/GP] `