2次元配列も定義できるようだが、 こちらはカギ括弧 [ ] は使えず、 丸括弧 ( ) を使う必要があるみたい。
| 2次元配列はこんなふうに |
real[int,int] a(2,2); a(1,1)=1; a(1,2)=2; a(2,1)=3; a(2,2)=4; |
| 2次元配列の例 (丸い括弧を使う) |
// operation_of_2Darray.edp
real[int,int] a(3,2);
a(0,0)=1; a(0,1)=2;
a(1,0)=3; a(1,1)=4;
a(2,0)=5; a(2,1)=6;
cout << "a.n=" << a.n << ", a.m=" << a.m << endl; // 3と2になる。
for (int i=0; i < a.n; i++) {
for (int j=0; j < a.m; j++)
cout << setw(4) << a(i,j) << " ";
cout << endl;
}
cout << "output by \"cout<<\"a=\"<<a<<endl;\"" << endl;
cout << "a=" << a << endl;
cout << "max of a=" << a.max << endl;
cout << "min of a=" << a.min << endl;
cout << "sum of a=" << a.sum << endl;
cout << "1-norm of a=" << a.l1 << endl;
cout << "2-norm of a=" << a.l2 << endl;
cout << "infty-norm of a=" << a.linfty << endl;
|
| 2次元配列の例 (丸い括弧を使う) |
$ FreeFem++ operation_of_2Darray.edp
-- FreeFem++ v4.14 (Mar 10 déc 2024 18:13:35 CET - git v4.15)
file : operation_of_2Darray.edp
Load: lg_fem lg_mesh lg_mesh3 eigenvalue
1 : // operation_of_2Darray.edp
2 :
3 : real[int,int] a(3,2);
4 : a(0,0)=1; a(0,1)=2;
5 : a(1,0)=3; a(1,1)=4;
6 : a(2,0)=5; a(2,1)=6;
7 : cout << "a.n=" << a.n << ", a.m=" << a.m << endl; // 3と2になる。
8 : for (int i=0; i < a.n; i++) {
9 : for (int j=0; j < a.m; j++)
10 : cout << setw(4) << a(i,j) << " ";
11 : cout << endl;
12 : }
13 : cout << "output by \"cout<<\"a=\"<<a<<endl;\"" << endl;
14 : cout << "a=" << a << endl;
15 :
16 : cout << "max of a=" << a.max << endl;
17 : cout << "min of a=" << a.min << endl;
18 : cout << "sum of a=" << a.sum << endl;
19 : cout << "1-norm of a=" << a.l1 << endl;
20 : cout << "2-norm of a=" << a.l2 << endl;
21 : cout << "infty-norm of a=" << a.linfty << endl;
22 : sizestack + 1024 =1168 ( 144 )
a.n=3, a.m=2
1 2
3 4
5 6
output by "cout<<"a="<<a<<endl;"
a=3 2
1 2
3 4
5 6
max of a=6
min of a=1
sum of a=21
1-norm of a=21
2-norm of a=9.53939
infty-norm of a=6
times: compile 0.010674s, execution 0.000136s, mpirank:0
CodeAlloc : nb ptr 4018, size :502616 mpirank: 0
Ok: Normal End
$
|