summaryrefslogtreecommitdiffstats
path: root/scilab_doc
diff options
context:
space:
mode:
authorFrancois Delebecque <Francois.Delebecque@inria.fr>2004-09-23 12:10:37 +0000
committerFrancois Delebecque <Francois.Delebecque@inria.fr>2004-09-23 12:10:37 +0000
commit539bd585a6dcab367a6345429dbe5c6ffc766134 (patch)
tree54a5dcb273128f07809c2c40e0b9021c493a4ba1 /scilab_doc
parent246f824bda43e3a71189c6f0cf00f7dc66c60d7a (diff)
downloadscilab-539bd585a6dcab367a6345429dbe5c6ffc766134.zip
scilab-539bd585a6dcab367a6345429dbe5c6ffc766134.tar.gz
updt
Diffstat (limited to 'scilab_doc')
-rwxr-xr-xscilab_doc/intro/diary/d1p.code4
-rwxr-xr-xscilab_doc/intro/diary/d1p15.code4
-rwxr-xr-xscilab_doc/intro/diary/d1p16.code37
-rwxr-xr-xscilab_doc/intro/diary/d2.10a.code1
-rwxr-xr-xscilab_doc/intro/diary/demo1.code32
-rwxr-xr-xscilab_doc/intro/diary/extract.code72
-rwxr-xr-xscilab_doc/intro/diary/list.code49
-rw-r--r--scilab_doc/intro/diary/loader.sce4
-rw-r--r--scilab_doc/intro/diary/myplus.c6
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 :
21s=poly(0,'s');p=1+2*s+s^2 21s=poly(0,'s');p=1+2*s+s^2
22diary(0) 22diary(0)
23diary('d1p41.dia')
24Params.tol=[0.01,0.002]; Params.errmsg='error message';
25Params.tol(2)
26diary(0)
23diary('d1p5.dia') 27diary('d1p5.dia')
24M=[p, p-1; p+1 ,2] 28M=[p, p-1; p+1 ,2]
25det(M) 29det(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
2save('myfile') 2save('myfile')
3//Request to the host system to perform a system command 3//Request to the host system to perform a system command
4unix_s('rm myfile') 4unix_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
6unix_w('date') 6unix_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 @@
1foo=['void foo(a,b,c)'; 1foo=['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) '
5write('foo.c',foo); //Editing 5 ' c[k] = a[k] + b[k];'
6unix_s('make foo.o') //Compiling 6 ' return(0);}'];
7link('foo.o','foo','C'); //Dynamic link 7
8//On line definition of myplus function. 8mputl(foo,'myplus.c'); //create a myplus.c file
9//(Calling external C code). 9
10deff('[c]=myplus(a,b)',... 10ilib_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
12myplus(5,7) 12exec loader.sce; //exec file created by ilib_for_link
13// to link the library (.so file or .dll file);
14
15function 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.
18c=call('myplus',m*n,1,'i',a,2,'d',b,3,'d',...
19 'out',[m,n],4,'d');
20endfunction
21
22myplus([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');
3t=poly(0,'t'); 3t=poly(0,'t');
4p=list(t^2+2*t^3,-t-t^2,t,1+0*t); 4p=list(t^2+2*t^3,-t-t^2,t,1+0*t);
5pst=makefunction(p) 5pst=makefunction(p)
6pst
7pst(1) 6pst(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
27Sp(1,10)==Sp(1,1) //boolean sparse matrix 27Sp(1,10)==Sp(1,1) //boolean sparse matrix
28 28
29// 3. LISTS 29// 3. LISTS/STRUCTURES
30L=list(a,-(1:5), Mp,['this','is';'a','list']) //list 30L=list(a,-(1:5), Mp,['this','is';'a','list']) //list
31L(2)(3) //sub-entry in list 31L(2)(3) //sub-entry in list
32Lt=tlist(['mylist','color','position','weight'],'blue',[0,1],10) //typed-list 32Lt=tlist(['mylist','color','position','weight'],'blue',[0,1],10) //typed-list
33Lt('color') //extracting 33Lt.color //extracting
34Lt('weight') //extracting 34Lt.weight //extracting
35//
36Struct.f1='hello' //Defining a structure.
37Struct.f2=rand(2,2);
38Struct.f2
39Struct.f2(2,1)
40
35A=diag([2,3,4]);B=[1 0;0 1;0 0];C=[1 -1 0];D=0*C*B;x0=[0;0;0]; 41A=diag([2,3,4]);B=[1 0;0 1;0 0];C=[1 -1 0];D=0*C*B;x0=[0;0;0];
36Sl=syslin('c',A,B,C,D,x0) //Standard state-space linear system 42Sl=syslin('c',A,B,C,D,x0) //Standard state-space linear system
37Sl.A, Sl.C //Retrieving elements of a typed list 43Sl.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
137ww=spec(H) 143ww=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');
144X'*H*X 150X'*H*X
145 151
146//Selection of user-defined eigenvalues (# 3 and 4 here); 152//Selection of user-defined eigenvalues;
147function flg=sel(x) 153function 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
150endfunction 157endfunction
151[X,d]=schur(H,sel) 158[X,d]=schur(H,sel)
152 159
153X'*H*X 160X'*H*X
154 161
155// With matrix pencil
156[X,d]=gschur(H,eye(H),sel)
157X'*H*X
158
159// block diagonalization 162// block diagonalization
160[ab,x,bs]=bdiag(H); 163[Hb,x,bs]=bdiag(H);
161 164
162inv(x)*H*x 165inv(x)*H*x //Compare with Hb
163 166
164// Matrix pencils 167// Matrix pencils
165E=rand(3,2)*rand(2,3); 168E=rand(3,2)*rand(2,3);
@@ -191,5 +194,6 @@ write('foo.c',foo);
191unix_s('make foo.o') //Compiling...(needs a compiler) 194unix_s('make foo.o') //Compiling...(needs a compiler)
192link('foo.o','foo','C') //Linking to Scilab 195link('foo.o','foo','C') //Linking to Scilab
193//5+7 by C function 196//5+7 by C function
194fort('foo',5,1,'d',7,2,'d','out',[1,1],3,'d') 197call('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 @@
1A=[1 2 3;4 5 6] 1A=[1 2 3;4 5 6];
2A(1,2) 2A(1,2); //Entry at row 1 and column 2
3A([1 1],2) 3A([1;1],2); //Same as [A(1,2);A(1,2)]
4A(:,1) 4A(:,1); //All rows, first column
5A(:,3:-1:1) 5A(:,3:-1:1) //all rows, first column reversed
6A(1) 6A(1); // First entry A(1,1)
7A(6) 7[A(6) A($)] //Last entry
8A(:) 8A(:); //All entries as a column
9A([%t %f %f %t]) 9A([%t %f %f %t]) //Selection of entries
10A([%t %f],[2 3]) 10A([%t %f],[2 3]) //...
11A(1:2,$-1) 11A(1:2,$-1); //rows 1 and 2 and column 2
12A($:-1:1,2) 12A($:-1:1,2); //reversed rows, column 2
13A($) 13x='test'; //string
14// 14x([1 1;1 1;1 1]) //string matrix
15x='test' 15B=[1/%s,(%s+1)/(%s-1)]; //Rational matrix
16x([1 1;1 1;1 1]) 16[B(1,1) B(1,$)] //Extract from rational matrix
17// 17B.num // the numerator
18B=[1/%s,(%s+1)/(%s-1)] 18A=[1 2 3;4 5 6];
19B(1,1) 19A(1,2)=10; //Changing A(1,2)
20B(1,$) 20A([1 1],2)=[-1;-2] //A(1,2)=-1; A(1,2)=-2;
21B(2) // the numerator 21A(:,1)=[8;5];
22// 22A(1,3:-1:1)=[77 44 99];
23A=[1 2 3;4 5 6] 23A(1,:)=10; //All entries of first row set to 10
24A(1,2)=10 24A(1)=%s; //A is now a polynomial matrix
25A([1 1],2)=[-1;-2] 25A($)=%s+1; //Changing last entry od=f A
26A(:,1)=[8;5] 26A(:)=1:6; //Re-assign all entries of A
27A(1,3:-1:1)=[77 44 99] 27A([%t %f],1)=33 //A(1,1)=33
28A(1,:)=10 28A(1:2,$-1)=[2;4];
29A(1)=%s 29A($:-1:1,1)=[8;7];
30A(6)=%s+1 30A($)=123;
31A(:)=1:6 31x='test';
32A([%t %f],1)=33 32x([4 5])=['4','5']; //String vector
33A(1:2,$-1)=[2;4] 33
34A($:-1:1,1)=[8;7] 34
35A($)=123
36//
37x='test'
38x([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 @@
1a=33;b=11;c=0; 1a=33;b=11;c=0;
2l=list();l(0)=a 2l=list();l(0)=a; //Add at begining
3l=list();l(1)=a 3l=list();l(1)=a; //Change first entry
4l=list(a);l(2)=b 4l=list(a);l(2)=b; //Add at end
5l=list(a);l(0)=b 5l=list(a);l(0)=b; //Add at begining
6l=list(a);l(1)=c 6l=list(a);l(1)=c;
7l=list();l(0)=null() 7l=list();l(0)=null(); //Empty list
8l=list();l(1)=null() 8l=list();l(1)=null();
9//
10i='i'; 9i='i';
11l=list(a,list(c,b),i);l(1)=null() 10l=list(a,list(c,b),i);l(1)=null();
12l=list(a,list(c,list(a,c,b),b),'h'); 11l=list(a,list(c,list(a,c,b),b),'h');
13l(2)(2)(3)=null() 12l(2)(2)(3)=null();
14//
15dts=list(1,tlist(['x';'a';'b'],10,[2 3])); 13dts=list(1,tlist(['x';'a';'b'],10,[2 3]));
16dts(2).a 14dts(2).a; //Field a in second entry of dts
17dts(2).b(1,2) 15dts(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// 17l=list(1,'qwerw',%s);
20l=list(1,'qwerw',%s) 18l(1)='Changed'; //modifying a list
21l(1)='Changed' 19l(0)='Added'; //Add at begining
22l(0)='Added' 20l(6)=['one more';'added']; //Undefined entries
23l(6)=['one more';'added']
24//
25dts=list(1,tlist(['x';'a';'b'],10,[2 3])); 21dts=list(1,tlist(['x';'a';'b'],10,[2 3]));
26dts(2).a=33 22dts(2).a=33; //Set field a of dts(2) to 33
27dts(2).b(1,2)=-100 23dts(2).b(1,2)=-100; //...
28//
29l=list(1,'qwerw',%s); 24l=list(1,'qwerw',%s);
30l(1) 25[a,b]=l([3 2]); //Defining both a and b
31[a,b]=l([3 2]) 26l($); //last entry
32l($) 27L=list(33,list(l,33)); //entry 2 of L is a list
33//
34L=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// ------------------------------------------------------
3myplus_path=get_absolute_file_path('loader.sce');
4link(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 @@
1int myplus(n, a, b, c)
2int *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);}