update the Doc
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@12001 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2f7c5cdd14
commit
153ffe45af
1 changed files with 107 additions and 2 deletions
|
|
@ -28,6 +28,7 @@
|
|||
<li><a href="#Scilab_nn13">Pointers</a>
|
||||
<li><a href="#Scilab_nn14">Structs</a>
|
||||
<li><a href="#Scilab_nn15">Arrays</a>
|
||||
<li><a href="#Scilab_nn16">Matrices</a>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -40,14 +41,14 @@
|
|||
</p>
|
||||
|
||||
<p>
|
||||
This chapter is intended to give an introduction to use the module. You should also read the SWIG documentation which is not specific to Scilab. Also, there are a dozen or so examples in the Examples/Scilab directory.
|
||||
This chapter is intended to give an introduction to use the module. You should also read the SWIG documentation which is not specific to Scilab. Also, there are a dozen or so examples in the Examples/Scilab directory. As Scilab doesn't really do objects, so in this module, it supports mainly C features: variables, functions, constants, enums, structs, unions, pointers, arrays and matrices.
|
||||
</p>
|
||||
|
||||
<H2><a name="Scilab_nn2"></a>36.1 Preliminaries</H2>
|
||||
|
||||
|
||||
<p>
|
||||
The current SWIG implemention is based on Scilab 5.1.1. Support for other higher versions has not been tested, nor has support for any OS other than Linux.
|
||||
The current SWIG implemention is based on Scilab 5.2.2. Support for other higher versions has not been tested, nor has support for any OS other than Linux.
|
||||
</p>
|
||||
|
||||
<H2><a name="Scilab_nn3"></a>36.2 Running SWIG</H2>
|
||||
|
|
@ -383,6 +384,110 @@ ans =
|
|||
0. 0.1428571 0.2857143 0.4285714 0.5714286 0.7142857 0.8571429
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Scilab_nn16"></a>36.3.9 Matrices</H3>
|
||||
<p>
|
||||
Scilab uses matrices a lot for numerical mathematics and scientific visualization. So supporting matrices would make scilab more convenient. For example:
|
||||
</p>
|
||||
<div class="code"><pre>%module example
|
||||
%inline %{
|
||||
double **new_matrix() {
|
||||
|
||||
int i;
|
||||
double **M;
|
||||
|
||||
M = (double **) malloc(4 * sizeof(double *));
|
||||
M[0] = (double *) malloc(16 * sizeof(double));
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
M[i] = M[0] + 4 * i;
|
||||
}
|
||||
return M;
|
||||
}
|
||||
|
||||
void set_m(double **M, int i, int j, double val) {
|
||||
M[i][j] = val;
|
||||
}
|
||||
|
||||
double get_m(double **M, int i, int j) {
|
||||
return M[i][j];
|
||||
}
|
||||
|
||||
void print_matrix(double **M) {
|
||||
|
||||
int i,j;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
printf("%10g ", M[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void mat_mult(double **m1, double **m2, double **m3) {
|
||||
|
||||
int i,j,k;
|
||||
double temp[4][4];
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
for (j = 0; j < 4; j++) {
|
||||
temp[i][j] = 0;
|
||||
for (k = 0; k < 4; k++)
|
||||
temp[i][j] += m1[i][k] * m2[k][j];
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
m3[i][j] = temp[i][j];
|
||||
}
|
||||
%}
|
||||
</pre></div>
|
||||
<p> When wrappered, it would generate the following funtion:
|
||||
</p>
|
||||
<p>_wrap_new_matrix(): generate a new matrix.
|
||||
</p>
|
||||
<p>_wrap_set_m(M, i, j, a): set M(i, j) to be value a.
|
||||
</p>
|
||||
<p>_wrap_get_m(M, i, j): get the value of M(i, j).
|
||||
</p>
|
||||
<p>_wrap_print_matrix(M): print the matrix M.
|
||||
</p>
|
||||
<p>_wrap_mat_mult(A, B, C): compute the A * B and the result is stored into C.
|
||||
</p>
|
||||
<p>So it could be used like this:
|
||||
</p>
|
||||
<div class="targetlang"><pre>
|
||||
--> exec loader.sce
|
||||
|
||||
--> x = new_matrix();
|
||||
--> for i = 0 : 3;
|
||||
--> for j = 0 : 3;
|
||||
--> set_m(x, i, j, i + j);
|
||||
--> end;
|
||||
--> end;
|
||||
|
||||
--> print_matrix(y);
|
||||
0 1 2 3
|
||||
1 2 3 4
|
||||
2 3 4 5
|
||||
3 4 5 6
|
||||
--> y = new_matrix();
|
||||
--> for i = 0 : 3;
|
||||
--> for j = 0 : 3;
|
||||
--> set_m(y, i, j, i - j);
|
||||
--> end;
|
||||
--> end;
|
||||
|
||||
--> print_matrix(y);
|
||||
0 -1 -2 -3
|
||||
1 0 -1 -2
|
||||
2 1 0 -1
|
||||
3 2 1 0
|
||||
--> z = new_matrix();
|
||||
--> mat_mult(x, y, z);
|
||||
--> print_matrix(z);
|
||||
14 8 2 -4
|
||||
20 10 0 -10
|
||||
26 12 -2 -16
|
||||
32 14 -4 -22
|
||||
</pre></div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue