[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6 配列


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6.1 newvect, vector, vect

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

:: 長さ len のベクトルを生成する.

vect([elements])

:: elements を要素とするベクトルを生成する.

return

ベクトル

len

自然数

list

リスト

elements

要素の並び

[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] ]
参照

newmat, matrix, size, ltov, vtol.


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6.2 ltov

ltov(list)

:: リストをベクトルに変換する.

return

ベクトル

list

リスト

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

newvect, vector, vect, vtol.


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6.3 vtol

vtol(vect)

:: ベクトルをリストに変換する.

return

リスト

vect

ベクトル

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

newvect, vector, vect, ltov.


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6.4 newbytearray

newbytearray(len,[listorstring])

:: 長さ len の byte array を生成する.

return

byte array

len

自然数

listorstring

リストまたは文字列

[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|
参照

newvect, vector, vect.


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6.5 newmat, matrix

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

:: rowcol 列の行列を生成する.

return

行列

row col

自然数

a b c d

任意

[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
参照

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


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6.6 mat, matr, matc

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

:: 行ベクトルの並びから行列を生成する.

matc(vector[,...])

:: 列ベクトルの並びから行列を生成する.

return

行列

vector

配列またはリスト

[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 ]
参照

newmat, matrix


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6.7 size

size(vect|mat)

:: [vect の長さ] または [mat の行数,mat の列数].

return

リスト

vect

ベクトル

mat

行列

[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]
参照

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


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6.8 det, nd_det, invmat

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

:: mat の行列式を求める.

invmat(mat)

:: mat の逆行列を求める.

return

det: 式, invmat: リスト

mat

行列

mod

素数

[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 ]
参照

newmat, matrix.


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

6.6.9 qsort

qsort(array[,func])

:: 一次元配列 array をソートする.

return

array (入力と同じ; 要素のみ入れ替わる)

array

一次元配列

func

比較用関数

[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 ]
参照

ord, vars.


[ << ] [ < ] [?] [ > ] [ >> ]         [??] [??] [???] [ ? ]

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

rowx(matrix,i,j)

:: 第 i 行と第 j 行を交換する.

rowm(matrix,i,c)

:: 第 i 行を c 倍する.

rowa(matrix,i,c)

:: 第 i 行に第 i 行の c 倍を加える.

colx(matrix,i,j)

:: 第 i 行と第 j 行を交換する.

colm(matrix,i,c)

:: 第 i 行を c 倍する.

cola(matrix,i,c)

:: 第 i 行に第 i 行の c 倍を加える.

return

行列

i, j

整数

c

係数

[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 ]
参照

newmat, matrix


[ << ] [ < ] [?] [ > ] [ >> ]

?????12? 15, 2017?texi2html 5.0????????????