[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6 Arrays


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.1 newvect, vector, vect

newvect(len[,list])
vector(len[,list])

:: Creates a new vector object with its length len.

vect([elements])

:: Creates a new vector object by elements.

return

vector

len

non-negative integer

list

list

elements

elements of the vector

[0] A=newvect(5);
[ 0 0 0 0 0 ]
[1] A=newvect(5,[1,2,3,4,[5,6]]);
[ 1 2 3 4 [5,6] ]
[2] A[0];
1
[3] A[4];
[5,6]
[4] size(A);
[5]
[5] length(A);
5
[6] vect(1,2,3,4,[5,6]);
[ 1 2 3 4 [5,6] ]
[7] def afo(V) { V[0] = x; }
[8] afo(A)$
[9] A;
[ x 2 3 4 [5,6] ]
References

newmat, matrix, size, ltov, vtol.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.2 ltov

ltov(list)

:: Converts a list into a vector.

return

vector

list

list

[3] A=[1,2,3];
[4] ltov(A);
[ 1 2 3 ]
References

newvect, vector, vect, vtol.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.3 vtol

vtol(vect)

:: Converts a vector into a list.

return

list

vect

vector

[3] A=newvect(3,[1,2,3]);
[ 1 2 3 ]
[4] vtol(A);
[1,2,3]
References

newvect, vector, vect, ltov.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.4 newbytearray

newbytearray(len,[listorstring])

:: Creates a new byte array.

return

byte array

len

non-negative integer

listorstring

list or string

[182] A=newbytearray(3);
|00 00 00|
[183] A=newbytearray(3,[1,2,3]);
|01 02 03|
[184] A=newbytearray(3,"abc");  
|61 62 63|
[185] A[0];
97
[186] A[1]=123;
123
[187] A;
|61 7b 63|
References

newvect, vector, vect.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.5 newmat, matrix

newmat(row,col [,[[a,b,...],[c,d,...],...]])
matrix(row,col [,[[a,b,...],[c,d,...],...]])

:: Creates a new matrix with row rows and col columns.

return

matrix

row col

non-negative integer

a b c d

arbitrary

[0] A = newmat(3,3,[[1,1,1],[x,y],[x^2]]);
[ 1 1 1 ]
[ x y 0 ]
[ x^2 0 0 ]
[1] det(A);
-y*x^2
[2] size(A);
[3,3]
[3] A[1];
[ x y 0 ]
[4] A[1][3];
getarray : Out of range
return to toplevel
References

newvect, vector, vect, size, det, nd_det, invmat.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.6 mat, matr, matc

mat(vector[,...])
matr(vector[,...])

:: Creates a new matrix by list of row vectors.

matc(vector[,...])

:: Creates a new matrix by list of column vectors.

return

matrix

vector

array or list

[0] matr([1,2,3],[4,5,6],[7,8]);
[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 0 ]
[1] matc([1,2,3],[4,5,6],[7,8]);
[ 1 4 7 ]
[ 2 5 8 ]
[ 3 6 0 ]
References

newmat, matrix


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.7 size

size(vect|mat)

:: A list containing the number of elements of the given vector, [size of vect], or a list containing row size and column size of the given matrix, [row size of mat, column size of mat].

return

list

vect

vector

mat

matrix

[0] A = newvect(4);
[ 0 0 0 0 ]
[1] size(A);
[4]
[2] length(A);
4
[3] B = newmat(2,3,[[1,2,3],[4,5,6]]);
[ 1 2 3 ]
[ 4 5 6 ]
[4] size(B);
[2,3]
References

car, cdr, cons, append, reverse, length, nmono.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.8 det, nd_det, invmat

det(mat[,mod])
nd_det(mat[,mod])

:: Determinant of mat.

invmat(mat)

:: Inverse matrix of mat.

return

det: expression, invmat: list

mat

matrix

mod

prime

[91] A=newmat(5,5)$                         
[92] V=[x,y,z,u,v];
[x,y,z,u,v]
[93] for(I=0;I<5;I++)for(J=0,B=A[I],W=V[I];J<5;J++)B[J]=W^J;
[94] A;
[ 1 x x^2 x^3 x^4 ]
[ 1 y y^2 y^3 y^4 ]
[ 1 z z^2 z^3 z^4 ]
[ 1 u u^2 u^3 u^4 ]
[ 1 v v^2 v^3 v^4 ]
[95] fctr(det(A));
[[1,1],[u-v,1],[-z+v,1],[-z+u,1],[-y+u,1],[y-v,1],[-y+z,1],[-x+u,1],
[-x+z,1],[-x+v,1],[-x+y,1]]
[96] A = newmat(3,3)$
[97] for(I=0;I<3;I++)for(J=0,B=A[I],W=V[I];J<3;J++)B[J]=W^J;
[98] A;
[ 1 x x^2 ]
[ 1 y y^2 ]
[ 1 z z^2 ]
[99] invmat(A);
[[ -z*y^2+z^2*y z*x^2-z^2*x -y*x^2+y^2*x ]
[ y^2-z^2 -x^2+z^2 x^2-y^2 ]
[ -y+z x-z -x+y ],(-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y]
[100] A*B[0];
[ (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y 0 0 ]
[ 0 (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y 0 ]
[ 0 0 (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y ]
[101] map(red,A*B[0]/B[1]);
[ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 1 ]
References

newmat, matrix.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.9 qsort

qsort(array[,func])

:: Sorts an array array.

return

array (The same as the input; Only the elements are exchanged.)

array

array

func

function for comparison

[0] qsort(newvect(10,[1,4,6,7,3,2,9,6,0,-1]));
[ -1 0 1 2 3 4 6 6 7 9 ]
[1] def rev(A,B) { return A>B?-1:(A<B?1:0); }
[2] qsort(newvect(10,[1,4,6,7,3,2,9,6,0,-1]),rev);
[ 9 7 6 6 4 3 2 1 0 -1 ]
References

ord, vars.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.10 rowx, rowm, rowa, colx, colm, cola

rowx(matrix,i,j)

:: Exchanges the i-th and j-th rows.

rowm(matrix,i,c)

:: Multiplies the i-th row by c.

rowa(matrix,i,c)

:: Appends c times the j-th row to the j-th row.

colx(matrix,i,j)

:: Exchanges the i-th and j-th columns.

colm(matrix,i,c)

:: Multiplies the i-th column by c.

cola(matrix,i,c)

:: Appends c times the j-th column to the j-th column.

return

matrix

i, j

integers

c

coefficient

[0] A=newmat(3,3,[[1,2,3],[4,5,6],[7,8,9]]);
[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 9 ]
[1] rowx(A,1,2)$
[2] A;
[ 1 2 3 ]
[ 7 8 9 ]
[ 4 5 6 ]
[3] rowm(A,2,x);
[ 1 2 3 ]
[ 7 8 9 ]
[ 4*x 5*x 6*x ]
[4] rowa(A,0,1,z);
[ 7*z+1 8*z+2 9*z+3 ]
[ 7 8 9 ]
[ 4*x 5*x 6*x ]
References

newmat, matrix


[ << ] [ < ] [ Up ] [ > ] [ >> ]

This document was generated on April 18, 2024 using texi2html 5.0.