diff options
author | Francois Delebecque <Francois.Delebecque@inria.fr> | 2004-09-23 12:10:37 +0000 |
---|---|---|
committer | Francois Delebecque <Francois.Delebecque@inria.fr> | 2004-09-23 12:10:37 +0000 |
commit | 539bd585a6dcab367a6345429dbe5c6ffc766134 (patch) | |
tree | 54a5dcb273128f07809c2c40e0b9021c493a4ba1 /scilab_doc | |
parent | 246f824bda43e3a71189c6f0cf00f7dc66c60d7a (diff) | |
download | scilab-539bd585a6dcab367a6345429dbe5c6ffc766134.zip scilab-539bd585a6dcab367a6345429dbe5c6ffc766134.tar.gz |
updt
Diffstat (limited to 'scilab_doc')
-rwxr-xr-x | scilab_doc/intro/diary/d1p.code | 4 | ||||
-rwxr-xr-x | scilab_doc/intro/diary/d1p15.code | 4 | ||||
-rwxr-xr-x | scilab_doc/intro/diary/d1p16.code | 37 | ||||
-rwxr-xr-x | scilab_doc/intro/diary/d2.10a.code | 1 | ||||
-rwxr-xr-x | scilab_doc/intro/diary/demo1.code | 32 | ||||
-rwxr-xr-x | scilab_doc/intro/diary/extract.code | 72 | ||||
-rwxr-xr-x | scilab_doc/intro/diary/list.code | 49 | ||||
-rw-r--r-- | scilab_doc/intro/diary/loader.sce | 4 | ||||
-rw-r--r-- | scilab_doc/intro/diary/myplus.c | 6 |
9 files changed, 114 insertions, 95 deletions
diff --git a/scilab_doc/intro/diary/d1p.code b/scilab_doc/intro/diary/d1p.code index fae91c8..453dd0f 100755 --- a/scilab_doc/intro/diary/d1p.code +++ b/scilab_doc/intro/diary/d1p.code | |||
@@ -20,6 +20,10 @@ p=poly([1 2 3],'z','coeff') | |||
20 | //p can also be defined by : | 20 | //p can also be defined by : |
21 | s=poly(0,'s');p=1+2*s+s^2 | 21 | s=poly(0,'s');p=1+2*s+s^2 |
22 | diary(0) | 22 | diary(0) |
23 | diary('d1p41.dia') | ||
24 | Params.tol=[0.01,0.002]; Params.errmsg='error message'; | ||
25 | Params.tol(2) | ||
26 | diary(0) | ||
23 | diary('d1p5.dia') | 27 | diary('d1p5.dia') |
24 | M=[p, p-1; p+1 ,2] | 28 | M=[p, p-1; p+1 ,2] |
25 | det(M) | 29 | det(M) |
diff --git a/scilab_doc/intro/diary/d1p15.code b/scilab_doc/intro/diary/d1p15.code index b634c93..1d4a6bd 100755 --- a/scilab_doc/intro/diary/d1p15.code +++ b/scilab_doc/intro/diary/d1p15.code | |||
@@ -1,7 +1,7 @@ | |||
1 | //Saving the environment in a file named : myfile | 1 | //Saving the environment in a file named : myfile |
2 | save('myfile') | 2 | save('myfile') |
3 | //Request to the host system to perform a system command | 3 | //Request to the host system to perform a system command |
4 | unix_s('rm myfile') | 4 | unix_s('rm myfile') //unix_s('del myfile'); |
5 | //Request to the host system with output in this Scilab window | 5 | //Request to the host system with output in this Scilab window |
6 | unix_w('date') | 6 | unix_w('date') //unix_w('dir') |
7 | 7 | ||
diff --git a/scilab_doc/intro/diary/d1p16.code b/scilab_doc/intro/diary/d1p16.code index b7c370c..ede0422 100755 --- a/scilab_doc/intro/diary/d1p16.code +++ b/scilab_doc/intro/diary/d1p16.code | |||
@@ -1,12 +1,25 @@ | |||
1 | foo=['void foo(a,b,c)'; | 1 | foo=['int myplus(n, a, b, c)' |
2 | 'double *a,*b,*c;' | 2 | 'int *n; double *a, *b, *c;' |
3 | '{ *c = *a + *b;}'] | 3 | '{int k;' |
4 | //A 3 x 1 matrix of strings | 4 | ' for (k = 0; k < *n; ++k) ' |
5 | write('foo.c',foo); //Editing | 5 | ' c[k] = a[k] + b[k];' |
6 | unix_s('make foo.o') //Compiling | 6 | ' return(0);}']; |
7 | link('foo.o','foo','C'); //Dynamic link | 7 | |
8 | //On line definition of myplus function. | 8 | mputl(foo,'myplus.c'); //create a myplus.c file |
9 | //(Calling external C code). | 9 | |
10 | deff('[c]=myplus(a,b)',... | 10 | ilib_for_link('myplus','myplus.o',[],"c"); //make a shared library |
11 | 'c=call(''foo'',a,1,''d'',b,2,''d'',''out'',[1,1],3,''d'')') | 11 | |
12 | myplus(5,7) | 12 | exec loader.sce; //exec file created by ilib_for_link |
13 | // to link the library (.so file or .dll file); | ||
14 | |||
15 | function c=myplus(a,b) | ||
16 | [m,n]=size(a); //assume size(b) == size(a)! | ||
17 | //a at position 2, b at 3 and c at 4. | ||
18 | c=call('myplus',m*n,1,'i',a,2,'d',b,3,'d',... | ||
19 | 'out',[m,n],4,'d'); | ||
20 | endfunction | ||
21 | |||
22 | myplus([1,2],[3,4]) | ||
23 | |||
24 | |||
25 | |||
diff --git a/scilab_doc/intro/diary/d2.10a.code b/scilab_doc/intro/diary/d2.10a.code index 218c999..1ab39a4 100755 --- a/scilab_doc/intro/diary/d2.10a.code +++ b/scilab_doc/intro/diary/d2.10a.code | |||
@@ -3,5 +3,4 @@ s=poly(0,'s'); | |||
3 | t=poly(0,'t'); | 3 | t=poly(0,'t'); |
4 | p=list(t^2+2*t^3,-t-t^2,t,1+0*t); | 4 | p=list(t^2+2*t^3,-t-t^2,t,1+0*t); |
5 | pst=makefunction(p) | 5 | pst=makefunction(p) |
6 | pst | ||
7 | pst(1) | 6 | pst(1) |
diff --git a/scilab_doc/intro/diary/demo1.code b/scilab_doc/intro/diary/demo1.code index 2854143..6c73776 100755 --- a/scilab_doc/intro/diary/demo1.code +++ b/scilab_doc/intro/diary/demo1.code | |||
@@ -26,12 +26,18 @@ Sp=sparse([1,2;4,5;3,10],[1,2,3]) //sparse matrix | |||
26 | 26 | ||
27 | Sp(1,10)==Sp(1,1) //boolean sparse matrix | 27 | Sp(1,10)==Sp(1,1) //boolean sparse matrix |
28 | 28 | ||
29 | // 3. LISTS | 29 | // 3. LISTS/STRUCTURES |
30 | L=list(a,-(1:5), Mp,['this','is';'a','list']) //list | 30 | L=list(a,-(1:5), Mp,['this','is';'a','list']) //list |
31 | L(2)(3) //sub-entry in list | 31 | L(2)(3) //sub-entry in list |
32 | Lt=tlist(['mylist','color','position','weight'],'blue',[0,1],10) //typed-list | 32 | Lt=tlist(['mylist','color','position','weight'],'blue',[0,1],10) //typed-list |
33 | Lt('color') //extracting | 33 | Lt.color //extracting |
34 | Lt('weight') //extracting | 34 | Lt.weight //extracting |
35 | // | ||
36 | Struct.f1='hello' //Defining a structure. | ||
37 | Struct.f2=rand(2,2); | ||
38 | Struct.f2 | ||
39 | Struct.f2(2,1) | ||
40 | |||
35 | A=diag([2,3,4]);B=[1 0;0 1;0 0];C=[1 -1 0];D=0*C*B;x0=[0;0;0]; | 41 | A=diag([2,3,4]);B=[1 0;0 1;0 0];C=[1 -1 0];D=0*C*B;x0=[0;0;0]; |
36 | Sl=syslin('c',A,B,C,D,x0) //Standard state-space linear system | 42 | Sl=syslin('c',A,B,C,D,x0) //Standard state-space linear system |
37 | Sl.A, Sl.C //Retrieving elements of a typed list | 43 | Sl.A, Sl.C //Retrieving elements of a typed list |
@@ -134,7 +140,7 @@ H=[1. 1. 1. 0.; | |||
134 | 1. 0. 1. 1.; | 140 | 1. 0. 1. 1.; |
135 | 0. 1. 2. -1]; | 141 | 0. 1. 2. -1]; |
136 | 142 | ||
137 | ww=spec(H) | 143 | ww=spec(H) //eigenvalues |
138 | 144 | ||
139 | // STABLE SUBSPACES | 145 | // STABLE SUBSPACES |
140 | [X,d]=schur(H,'cont'); | 146 | [X,d]=schur(H,'cont'); |
@@ -143,23 +149,20 @@ X'*H*X | |||
143 | [X,d]=schur(H,'disc'); | 149 | [X,d]=schur(H,'disc'); |
144 | X'*H*X | 150 | X'*H*X |
145 | 151 | ||
146 | //Selection of user-defined eigenvalues (# 3 and 4 here); | 152 | //Selection of user-defined eigenvalues; |
147 | function flg=sel(x) | 153 | function flg=sel(x) |
148 | flg=0,ev=x(2)/x(3), | 154 | //x=tested eigenval. flg=1 iff x is selected. |
149 | if abs(ev-ww(3))<0.0001|abs(ev-ww(4))<0.00001 then flg=1,end | 155 | flg=0; |
156 | if abs(x)< 1 then flg=1,end | ||
150 | endfunction | 157 | endfunction |
151 | [X,d]=schur(H,sel) | 158 | [X,d]=schur(H,sel) |
152 | 159 | ||
153 | X'*H*X | 160 | X'*H*X |
154 | 161 | ||
155 | // With matrix pencil | ||
156 | [X,d]=gschur(H,eye(H),sel) | ||
157 | X'*H*X | ||
158 | |||
159 | // block diagonalization | 162 | // block diagonalization |
160 | [ab,x,bs]=bdiag(H); | 163 | [Hb,x,bs]=bdiag(H); |
161 | 164 | ||
162 | inv(x)*H*x | 165 | inv(x)*H*x //Compare with Hb |
163 | 166 | ||
164 | // Matrix pencils | 167 | // Matrix pencils |
165 | E=rand(3,2)*rand(2,3); | 168 | E=rand(3,2)*rand(2,3); |
@@ -191,5 +194,6 @@ write('foo.c',foo); | |||
191 | unix_s('make foo.o') //Compiling...(needs a compiler) | 194 | unix_s('make foo.o') //Compiling...(needs a compiler) |
192 | link('foo.o','foo','C') //Linking to Scilab | 195 | link('foo.o','foo','C') //Linking to Scilab |
193 | //5+7 by C function | 196 | //5+7 by C function |
194 | fort('foo',5,1,'d',7,2,'d','out',[1,1],3,'d') | 197 | call('foo',5,1,'d',7,2,'d','out',[1,1],3,'d') |
198 | |||
195 | 199 | ||
diff --git a/scilab_doc/intro/diary/extract.code b/scilab_doc/intro/diary/extract.code index cb0fe10..17e715e 100755 --- a/scilab_doc/intro/diary/extract.code +++ b/scilab_doc/intro/diary/extract.code | |||
@@ -1,38 +1,34 @@ | |||
1 | A=[1 2 3;4 5 6] | 1 | A=[1 2 3;4 5 6]; |
2 | A(1,2) | 2 | A(1,2); //Entry at row 1 and column 2 |
3 | A([1 1],2) | 3 | A([1;1],2); //Same as [A(1,2);A(1,2)] |
4 | A(:,1) | 4 | A(:,1); //All rows, first column |
5 | A(:,3:-1:1) | 5 | A(:,3:-1:1) //all rows, first column reversed |
6 | A(1) | 6 | A(1); // First entry A(1,1) |
7 | A(6) | 7 | [A(6) A($)] //Last entry |
8 | A(:) | 8 | A(:); //All entries as a column |
9 | A([%t %f %f %t]) | 9 | A([%t %f %f %t]) //Selection of entries |
10 | A([%t %f],[2 3]) | 10 | A([%t %f],[2 3]) //... |
11 | A(1:2,$-1) | 11 | A(1:2,$-1); //rows 1 and 2 and column 2 |
12 | A($:-1:1,2) | 12 | A($:-1:1,2); //reversed rows, column 2 |
13 | A($) | 13 | x='test'; //string |
14 | // | 14 | x([1 1;1 1;1 1]) //string matrix |
15 | x='test' | 15 | B=[1/%s,(%s+1)/(%s-1)]; //Rational matrix |
16 | x([1 1;1 1;1 1]) | 16 | [B(1,1) B(1,$)] //Extract from rational matrix |
17 | // | 17 | B.num // the numerator |
18 | B=[1/%s,(%s+1)/(%s-1)] | 18 | A=[1 2 3;4 5 6]; |
19 | B(1,1) | 19 | A(1,2)=10; //Changing A(1,2) |
20 | B(1,$) | 20 | A([1 1],2)=[-1;-2] //A(1,2)=-1; A(1,2)=-2; |
21 | B(2) // the numerator | 21 | A(:,1)=[8;5]; |
22 | // | 22 | A(1,3:-1:1)=[77 44 99]; |
23 | A=[1 2 3;4 5 6] | 23 | A(1,:)=10; //All entries of first row set to 10 |
24 | A(1,2)=10 | 24 | A(1)=%s; //A is now a polynomial matrix |
25 | A([1 1],2)=[-1;-2] | 25 | A($)=%s+1; //Changing last entry od=f A |
26 | A(:,1)=[8;5] | 26 | A(:)=1:6; //Re-assign all entries of A |
27 | A(1,3:-1:1)=[77 44 99] | 27 | A([%t %f],1)=33 //A(1,1)=33 |
28 | A(1,:)=10 | 28 | A(1:2,$-1)=[2;4]; |
29 | A(1)=%s | 29 | A($:-1:1,1)=[8;7]; |
30 | A(6)=%s+1 | 30 | A($)=123; |
31 | A(:)=1:6 | 31 | x='test'; |
32 | A([%t %f],1)=33 | 32 | x([4 5])=['4','5']; //String vector |
33 | A(1:2,$-1)=[2;4] | 33 | |
34 | A($:-1:1,1)=[8;7] | 34 | |
35 | A($)=123 | ||
36 | // | ||
37 | x='test' | ||
38 | x([4 5])=['4','5'] | ||
diff --git a/scilab_doc/intro/diary/list.code b/scilab_doc/intro/diary/list.code index ee984e3..2c4524c 100755 --- a/scilab_doc/intro/diary/list.code +++ b/scilab_doc/intro/diary/list.code | |||
@@ -1,35 +1,28 @@ | |||
1 | a=33;b=11;c=0; | 1 | a=33;b=11;c=0; |
2 | l=list();l(0)=a | 2 | l=list();l(0)=a; //Add at begining |
3 | l=list();l(1)=a | 3 | l=list();l(1)=a; //Change first entry |
4 | l=list(a);l(2)=b | 4 | l=list(a);l(2)=b; //Add at end |
5 | l=list(a);l(0)=b | 5 | l=list(a);l(0)=b; //Add at begining |
6 | l=list(a);l(1)=c | 6 | l=list(a);l(1)=c; |
7 | l=list();l(0)=null() | 7 | l=list();l(0)=null(); //Empty list |
8 | l=list();l(1)=null() | 8 | l=list();l(1)=null(); |
9 | // | ||
10 | i='i'; | 9 | i='i'; |
11 | l=list(a,list(c,b),i);l(1)=null() | 10 | l=list(a,list(c,b),i);l(1)=null(); |
12 | l=list(a,list(c,list(a,c,b),b),'h'); | 11 | l=list(a,list(c,list(a,c,b),b),'h'); |
13 | l(2)(2)(3)=null() | 12 | l(2)(2)(3)=null(); |
14 | // | ||
15 | dts=list(1,tlist(['x';'a';'b'],10,[2 3])); | 13 | dts=list(1,tlist(['x';'a';'b'],10,[2 3])); |
16 | dts(2).a | 14 | dts(2).a; //Field a in second entry of dts |
17 | dts(2).b(1,2) | 15 | dts(2).b(1,2); // entry (1,2) of matrix dts(2).b |
18 | [a,b]=dts(2)(['a','b']) | 16 | [a,b]=dts(2)(['a','b']); //Assign two variables |
19 | // | 17 | l=list(1,'qwerw',%s); |
20 | l=list(1,'qwerw',%s) | 18 | l(1)='Changed'; //modifying a list |
21 | l(1)='Changed' | 19 | l(0)='Added'; //Add at begining |
22 | l(0)='Added' | 20 | l(6)=['one more';'added']; //Undefined entries |
23 | l(6)=['one more';'added'] | ||
24 | // | ||
25 | dts=list(1,tlist(['x';'a';'b'],10,[2 3])); | 21 | dts=list(1,tlist(['x';'a';'b'],10,[2 3])); |
26 | dts(2).a=33 | 22 | dts(2).a=33; //Set field a of dts(2) to 33 |
27 | dts(2).b(1,2)=-100 | 23 | dts(2).b(1,2)=-100; //... |
28 | // | ||
29 | l=list(1,'qwerw',%s); | 24 | l=list(1,'qwerw',%s); |
30 | l(1) | 25 | [a,b]=l([3 2]); //Defining both a and b |
31 | [a,b]=l([3 2]) | 26 | l($); //last entry |
32 | l($) | 27 | L=list(33,list(l,33)); //entry 2 of L is a list |
33 | // | ||
34 | L=list(33,list(l,33)) | ||
35 | 28 | ||
diff --git a/scilab_doc/intro/diary/loader.sce b/scilab_doc/intro/diary/loader.sce new file mode 100644 index 0000000..2d4f257 --- /dev/null +++ b/scilab_doc/intro/diary/loader.sce | |||
@@ -0,0 +1,4 @@ | |||
1 | // generated by builder.sce: Please do not edit this file | ||
2 | // ------------------------------------------------------ | ||
3 | myplus_path=get_absolute_file_path('loader.sce'); | ||
4 | link(myplus_path+'libmyplus.so',['myplus'],'c'); | ||
diff --git a/scilab_doc/intro/diary/myplus.c b/scilab_doc/intro/diary/myplus.c new file mode 100644 index 0000000..694cbae --- /dev/null +++ b/scilab_doc/intro/diary/myplus.c | |||
@@ -0,0 +1,6 @@ | |||
1 | int myplus(n, a, b, c) | ||
2 | int *n; double *a, *b, *c; | ||
3 | {int k; | ||
4 | for (k = 0; k < *n; ++k) | ||
5 | c[k] = a[k] + b[k]; | ||
6 | return(0);} | ||