7
'string' //character string
8
z=poly(0,'z') // polynomial with variable 'z' and with one root at zero
9
p=1+3*z+4.5*z^2 //polynomial
15
5 9 -1] //3 x 3 constant matrix
17
b=[%t,%f] //1 x 2 boolean matrix
20
'a' ,'matrix'] //2 x 2 matrix of strings
23
1,z*p] //2 x 2 polynomial matrix
25
F=Mp/poly([1+%i 1-%i 1],'z') //rational matrix
27
Sp=sparse([1,2;4,5;3,10],[1,2,3]) //sparse matrix
29
Sp(1,10)==Sp(1,1) //boolean sparse matrix
32
L=list(a,-(1:5), Mp,['this','is';'a','list']) //list
33
L(2)(3) //sub-entry in list
34
Lt=tlist(['mylist','color','position','weight'],'blue',[0,1],10) //typed-list
35
Lt('color') //extracting
36
Lt('weight') //extracting
37
A=diag([2,3,4]);B=[1 0;0 1;0 0];C=[1 -1 0];D=0*C*B;x0=[0;0;0];
38
Sl=syslin('c',A,B,C,D,x0) //Standard state-space linear system
39
Sl("A"), Sl("C") //Retrieving elements of a typed list
40
Slt=ss2tf(Sl) // Transfer matrix
41
Slt('num'), Slt('den')
43
v=1:5;W=v'*v //constant matrix multiplication
44
W(1,:) //extracting first row
45
W(:,$) //extracting last column
46
Mp'*Mp+eye() //polynomial matrix
47
Mp1=Mp(1,1)+4.5*%i //complex
48
Fi=C*(z*eye()-A)^(-1)*B; //transfer function evaluation
49
F(:,1)*Fi //operations with rationals
50
M=[Mp -Mp; Mp' Mp+eye()] //concatenation of polynomial matrices
51
[Fi, Fi(:,1)] // ... or rationals
53
Num=F('num');Den=F('den'); //operation on transfer matrix
55
// SOME NUMERICAL PRIMITIVES
58
inv(Sl*Sl') //Product of two linear systems and inverse
59
w=ss2tf(ans) //Transfer function representation
60
w1=inv(ss2tf(Sl)*ss2tf(Sl')) //Product of two transfer functions and inverse
62
A=rand(3,3);;B=rand(3,1);n=contr(A,B) //Controllability
63
K=ppol(A,B,[-1-%i -1+%i -1]) //Pole placement
64
poly(A-B*K,'z')-poly([-1-%i -1+%i -1],'z') //Check...
67
ss=fft(s(1:128),-1); //FFT
69
plot2d3("enn",1,abs(ss)'); //simple plot
72
// ON LINE DEFINITION OF FUNCTION
73
deff('[x]=fact(n)','if n==0 then x=1,else x=n*fact(n-1),end')
76
deff('[f,g,ind]=rosenbro(x,ind)', 'a=x(2)-x(1)^2 , b=1-x(2) ,...
77
f=100.*a^2 + b^2 , g(1)=-400.*x(1)*a , g(2)=200.*a -2.*b ');
78
[f,x,g]=optim(rosenbro,[2;2],'qn')
83
deff('[ydot]=f(t,y)','ydot=a*y');
84
e(:,1)-ode([1;0;0],0,1,f)
88
h=[1/s,1/(s+1);1/s/(s+1),1/(s+2)/(s+2)]
93
// EXAMPLE: SECOND ORDER SYSTEM ANALYSIS
94
sl=syslin('c',1/(s*s+0.2*s+1))
97
y=csim('step',instants,sl);
98
xbasc();plot2d(instants',y')
99
// Delayed step response
100
deff('[in]=u(t)','if t<3 then in=0;else in=1;end');
101
y1=csim(u,instants,sl);plot2d(instants',y1');
104
yi=csim('imp',instants,sl);xbasc();plot2d(instants',yi');
105
yi1=csim('step',instants,s*sl);plot2d(instants',yi1');
109
sld=dscr(tf2ss(sl),0.05);
114
xbasc();plot(instants,yyy)
117
u=0*ones(instants);u(1)=1/dt;
119
xbasc();plot(instants,yy)
121
// system interconnexion
127
// change of variable
129
horner(h,(1-z)/(1+z)) //bilinear transform
140
[X,d]=schur(H,'cont');
143
[X,d]=schur(H,'disc');
146
//Selection of user-defined eigenvalues (# 3 and 4 here);
147
function [flg]=sel(x)
149
if abs(x-ww(3))<0.0001|abs(x-ww(4))<0.00001 then flg=%t,end
156
// With matrix pencil
157
function [flg]=sel(x,y)
159
if abs(x/y-ww(3))<0.0001|abs(x/y-ww(4))<0.00001 then flg=%t,end
162
[X,d]=schur(H,eye(H),sel)
165
// block diagonalization
171
E=rand(3,2)*rand(2,3);
172
A=rand(3,2)*rand(2,3);
175
w=det(s*E-A) //determinant
177
al./(be+%eps*ones(be))
179
[Ns,d]=coffg(s*E-A); //inverse of polynomial matrix;
181
[Q,M,i1]=pencan(E,A); // Canonical form;
186
write(%io(2),'pause command...');
187
write(%io(2),'TO CONTINUE...');
188
write(%io(2),'ENTER ''resume (or return) or click on resume!!''');
191
// CALLING EXTERNAL ROUTINE
193
foo=['void foo(double *a,double *b,double *c)';
194
'{ *c = *a + *b; }' ];
196
// we use TMPDIR for compilation
198
if ~c_link('foo') then
202
ilib_for_link(['foo'],'foo.o',[],"c");
208
call('foo',5,1,'d',7,2,'d','out',[1,1],3,'d')