diff options
author | Francois Delebecque <Francois.Delebecque@inria.fr> | 2004-09-23 14:31:36 +0000 |
---|---|---|
committer | Francois Delebecque <Francois.Delebecque@inria.fr> | 2004-09-23 14:31:36 +0000 |
commit | f6dd92e366bba70a1712e90d272086c61f3676fe (patch) | |
tree | adafb377e86f917fb289a2bbc7d2d2c73dfac17c /scilab_doc | |
parent | 5fbd13c8520a5dc9fc42f83d4d250036c5d4474f (diff) | |
download | scilab-f6dd92e366bba70a1712e90d272086c61f3676fe.zip scilab-f6dd92e366bba70a1712e90d272086c61f3676fe.tar.gz |
new
Diffstat (limited to 'scilab_doc')
-rwxr-xr-x | scilab_doc/intro/Makefile | 2 | ||||
-rwxr-xr-x | scilab_doc/intro/appendices.tex | 574 | ||||
-rwxr-xr-x | scilab_doc/intro/chap0.tex | 28 |
3 files changed, 337 insertions, 267 deletions
diff --git a/scilab_doc/intro/Makefile b/scilab_doc/intro/Makefile index e9bedef..3bf7a03 100755 --- a/scilab_doc/intro/Makefile +++ b/scilab_doc/intro/Makefile | |||
@@ -31,7 +31,7 @@ distclean:: | |||
31 | intro_pdf.* *.tmp Intro_pdf.ps *.hind *.haux *.html intro-html*.gif\ | 31 | intro_pdf.* *.tmp Intro_pdf.ps *.hind *.haux *.html intro-html*.gif\ |
32 | intro-html.image.tex *_motif.gif | 32 | intro-html.image.tex *_motif.gif |
33 | 33 | ||
34 | SUBDIRS = diary figures fort macros | 34 | SUBDIRS = diary figures macros |
35 | 35 | ||
36 | subs: | 36 | subs: |
37 | @case '${MFLAGS}' in *[ik]*) set +e;; esac; \ | 37 | @case '${MFLAGS}' in *[ik]*) set +e;; esac; \ |
diff --git a/scilab_doc/intro/appendices.tex b/scilab_doc/intro/appendices.tex index c6039a2..db827bd 100755 --- a/scilab_doc/intro/appendices.tex +++ b/scilab_doc/intro/appendices.tex | |||
@@ -1,286 +1,354 @@ | |||
1 | % Copyright INRIA | 1 | % Copyright INRIA |
2 | 2 | ||
3 | \appendix | 3 | \appendix |
4 | \chapter{Demo session} | 4 | |
5 | We give here the Scilab session corresponding to the first demo. | 5 | \chapter{Linear system representation} |
6 | 6 | Linear systems are treated as specific typed lists {\tt tlist}. | |
7 | \input{diary/demo1.dia} | 7 | The basic function which is used for defining linear systems is {\tt syslin}. |
8 | 8 | This function receives as parameters the constant matrices which | |
9 | \chapter{System interconnexion} | 9 | define a linear system in state-space form or, in the case of |
10 | 10 | system in transfer form, its input must be a rational matrix. | |
11 | %\section{System Interconnection} | 11 | To be more specific, the calling sequence of {\tt syslin} is |
12 | The purpose of this appendix is to illustrate some | 12 | either {\tt Sl=syslin('dom',A,B,C,D,x0)} or {\tt Sl=syslin('dom',trmat)}. |
13 | of the more sophisticated aspects of Scilab by the way of an example. | 13 | {\tt dom} is one of the character strings {\tt 'c'} or {\tt 'd'} |
14 | The example shows how Scilab can be used to symbolically represent | 14 | for continuous time or discrete time systems respectively. |
15 | the inter-connection of multiple systems which in turn can | 15 | It is useful to note that {\tt D} can be a polynomial matrix |
16 | then be used to numerically evaluate the performance of the | 16 | (improper systems); {\tt D} and {\tt x0} are optional arguments. |
17 | inter-connected systems. The symbolic representation of the | 17 | {\tt trmat} is a rational matrix i.e. it is defined as a matrix |
18 | inter-connected systems is done with a function called {\tt bloc2exp} | 18 | of rationals (ratios of polynomials). {\tt syslin} just converts |
19 | \index{bloc2exp@{\tt bloc2exp}} | 19 | its arguments (e.g. the four matrices A,B,C,D) into a typed |
20 | and the evaluation of the resulting system is done with | 20 | list {\tt Sl}. For state space representation {\tt Sl} is |
21 | {\tt evstr}\index{evstr@{\tt evstr}}. | 21 | the {\tt tlist(['lss','A','B','C','D'],A,B,C,D,'dom')}. This tlist |
22 | 22 | representation allows to access the A-matrix i.e. the second entry of | |
23 | The example illustrates the symbolic inter-connection of the | 23 | {\tt Sl} by the syntax {\tt Sl('A')} (equivalent to {\tt Sl(2)}). |
24 | systems shown in Figure~\ref{fa.1}\index{linear systems!inter-connection of}. | 24 | Conversion from a representation to another is done by {\tt ss2tf} |
25 | or {\tt tf2ss}. Improper systems are also treated. {\tt syslin} | ||
26 | defines linear systems as specific {\tt tlist}. ({\tt help syslin}). | ||
27 | |||
28 | \input{diary/syslin.dia} | ||
29 | |||
30 | The list representation allows manipulating linear systems as | ||
31 | abstract data objects. For example, the linear system can be combined | ||
32 | with other linear systems or the transfer function representation of | ||
33 | the linear system can be obtained as was done above using {\tt ss2tf}. | ||
34 | Note that the transfer function representation of the linear system | ||
35 | is itself a tlist. | ||
36 | A very useful aspect of the manipulation of systems | ||
37 | is that a system can be handled as a data object. | ||
38 | Linear systems can be | ||
39 | inter-connected\index{linear systems!inter-connection of}, | ||
40 | their representation | ||
41 | can easily be changed from state-space to transfer function | ||
42 | and vice versa. | ||
43 | |||
44 | The inter-connection of linear systems can be made | ||
45 | as illustrated in Figure~\ref{f3.2}. | ||
25 | % | 46 | % |
26 | \begin{figure} | 47 | \begin{figure} |
48 | |||
49 | %BEGIN IMAGE | ||
27 | \begin{center} | 50 | \begin{center} |
28 | \begin{picture}(360,204) | 51 | \begin{picture}(200,330)(0,-60) |
29 | 52 | ||
30 | \put(80,85){\framebox(40,30){\tt Model}} | 53 | \put(180,280){\makebox(0,0)[lb]{\tt S2*S1}} |
31 | \put(150,85){\framebox(40,30){\tt Reg}} | 54 | \put(9,280){\circle{2}} |
32 | \put(240,85){\framebox(40,30){\tt Proc}} | 55 | \put(10,280){\vector(1,0){20}} |
33 | \put(120,140){\framebox(40,30){\tt FF}} | 56 | \put(30,270){\framebox(30,20){$S_1$}} |
34 | \put(190,30){\framebox(40,30){\tt Sensor}} | 57 | \put(60,280){\vector(1,0){30}} |
35 | \put(210,100){\framebox(0,0){\tt +}} | 58 | \put(90,270){\framebox(30,20){$S_2$}} |
36 | 59 | \put(120,280){\vector(1,0){20}} | |
37 | \put(35,95){\tt U} | 60 | \put(141,280){\circle{2}} |
38 | \put(315,95){\tt Y} | 61 | |
39 | \put(315,125){\tt UP} | 62 | \put(180,220){\makebox(0,0)[lb]{\tt S1+S2}} |
40 | 63 | \put(29,220){\circle{2}} | |
41 | \put(50,100){\vector(1,0){30}} | 64 | \put(30,220){\line(1,0){20}} |
42 | \put(120,100){\vector(1,0){30}} | 65 | \put(50,220){\circle*{2}} |
43 | \put(190,100){\vector(1,0){15}} | 66 | \put(50,200){\line(0,1){40}} |
44 | \put(215,100){\vector(1,0){25}} | 67 | \put(50,200){\vector(1,0){20}} |
45 | \put(210,155){\vector(0,-1){50}} | 68 | \put(50,240){\vector(1,0){20}} |
46 | \put(295,45){\vector(-1,0){65}} | 69 | \put(70,190){\framebox(30,20){$S_2$}} |
47 | \put(65,155){\vector(1,0){55}} | 70 | \put(70,230){\framebox(30,20){$S_1$}} |
48 | \put(170,45){\vector(0,1){40}} | 71 | \put(100,200){\line(1,0){20}} |
49 | \put(225,130){\vector(1,0){85}} | 72 | \put(100,240){\line(1,0){20}} |
50 | \put(280,100){\vector(1,0){30}} | 73 | \put(120,240){\vector(0,-1){15}} |
51 | 74 | \put(120,200){\vector(0,1){15}} | |
52 | \put(65,100){\line(0,1){55}} | 75 | \put(120,220){\circle{10}} |
53 | \put(160,155){\line(1,0){50}} | 76 | \put(120,220){\framebox(0,0){$+$}} |
54 | \put(170,45){\line(1,0){20}} | 77 | \put(125,220){\vector(1,0){15}} |
55 | \put(225,100){\line(0,1){30}} | 78 | \put(141,220){\circle{2}} |
56 | \put(295,100){\line(0,-1){55}} | 79 | |
57 | 80 | \put(180,140){\makebox(0,0)[lb]{\tt [S1,S2]}} | |
58 | \put(210,100){\circle{10}} | 81 | \put(49,160){\circle{2}} |
59 | \put(48,100){\circle{2}} | 82 | \put(49,120){\circle{2}} |
60 | \put(310,100){\circle{2}} | 83 | \put(50,120){\vector(1,0){20}} |
61 | \put(310,130){\circle{2}} | 84 | \put(50,160){\vector(1,0){20}} |
62 | \put(65,100){\circle*{2}} | 85 | \put(70,110){\framebox(30,20){$S_2$}} |
63 | \put(225,100){\circle*{2}} | 86 | \put(70,150){\framebox(30,20){$S_1$}} |
64 | \put(295,100){\circle*{2}} | 87 | \put(100,120){\line(1,0){20}} |
88 | \put(100,160){\line(1,0){20}} | ||
89 | \put(120,160){\vector(0,-1){15}} | ||
90 | \put(120,120){\vector(0,1){15}} | ||
91 | \put(120,140){\circle{10}} | ||
92 | \put(120,140){\framebox(0,0){$+$}} | ||
93 | \put(125,140){\vector(1,0){15}} | ||
94 | \put(141,140){\circle{2}} | ||
65 | 95 | ||
96 | \put(180,50){\makebox(0,0)[lb]{\tt [S1 ; S2]}} | ||
97 | \put(49,50){\circle{2}} | ||
98 | \put(50,50){\line(1,0){20}} | ||
99 | \put(70,50){\circle*{2}} | ||
100 | \put(70,30){\line(0,1){40}} | ||
101 | \put(70,30){\vector(1,0){20}} | ||
102 | \put(70,70){\vector(1,0){20}} | ||
103 | \put(90,20){\framebox(30,20){$S_2$}} | ||
104 | \put(90,60){\framebox(30,20){$S_1$}} | ||
105 | \put(120,30){\vector(1,0){20}} | ||
106 | \put(120,70){\vector(1,0){20}} | ||
107 | \put(141,30){\circle{2}} | ||
108 | \put(141,70){\circle{2}} | ||
109 | |||
110 | \put(180,-40){\makebox(0,0)[lb]{\tt S1/.S2}} | ||
111 | \put(70,-20){\circle{10}} | ||
112 | \put(70,-20){\framebox(0,0){$+$}} | ||
113 | \put(34,-20){\vector(1,0){30}} | ||
114 | \put(33,-20){\circle{2}} | ||
115 | \put(70,-60){\line(0,1){40}} | ||
116 | \put(70,-60){\line(1,0){20}} | ||
117 | \put(70,-20){\vector(1,0){20}} | ||
118 | \put(90,-70){\framebox(30,20){$S_2$}} | ||
119 | \put(90,-30){\framebox(30,20){$S_1$}} | ||
120 | \put(140,-60){\vector(-1,0){20}} | ||
121 | \put(120,-20){\line(1,0){20}} | ||
122 | \put(141,-20){\circle{2}} | ||
123 | \put(140,-60){\line(0,1){40}} | ||
66 | \end{picture} | 124 | \end{picture} |
67 | \end{center} | 125 | \end{center} |
68 | \caption{Inter-Connected Systems} | 126 | %END IMAGE |
69 | \label{fa.1} | 127 | %HEVEA\imageflush |
128 | |||
129 | \caption{Inter-Connection of Linear Systems} | ||
130 | \label{f3.2} | ||
70 | \end{figure} | 131 | \end{figure} |
71 | % | 132 | % |
72 | Figure~\ref{fa.1} illustrates the classic regulator problem\index{regulator} | 133 | For each of the possible inter-connections of two systems |
73 | where the block labeled {\tt Proc} is to be controlled | 134 | {\tt S1} and {\tt S2} the command which makes the inter-connection |
74 | using feedback from the {\tt Sensor} block and {\tt Reg} block. | 135 | is shown on the right side of the corresponding block diagram in |
75 | The {\tt Reg} block compares the output from the {\tt Model} | 136 | Figure~\ref{f3.2}. Note that feedback interconnection is performed by |
76 | block to the output from the {\tt Sensor} block to decide how to | 137 | \verb!S1/.S2!. |
77 | regulate the {\tt Proc} block. There is also a feed-forward | 138 | |
78 | block which filters the input signal {\tt U} to the {\tt Proc} | 139 | The representation of linear systems can be in state-space |
79 | block. The outputs of the system are {\tt Y} and {\tt UP}. | 140 | form or in transfer function form. These two representations can |
80 | 141 | be interchanged by using the functions | |
81 | The system illustrated in Figure~\ref{fa.1} can | 142 | {\tt tf2ss}\index{linear systems!{\tt tf2ss}}\index{tf2ss@{\tt tf2ss}} and |
82 | be represented in Scilab by using the function {\tt bloc2exp}. | 143 | {\tt ss2tf}\index{linear systems!{\tt ss2tf}}\index{ss2tf@{\tt ss2tf}} |
83 | The use of {\tt bloc2exp} is illustrated in the following Scilab | 144 | which change the representations of systems from transfer function |
84 | session. | 145 | to state-space and from state-space to transfer function, respectively. |
85 | There a two kinds of objects: ``transfer'' and ``links''. The example | 146 | An example of the creation, the change in representation, and the |
86 | considered here admits 5 transfers and 7 links. | 147 | inter-connection of linear systems is demonstrated in the following |
87 | First the transfer are defined in a symbolic manner. Then links | 148 | Scilab session. |
88 | are defined and an ``interconnected system'' is defined as | 149 | |
89 | a specific list. The function {\tt bloc2exp} evaluates symbolically | 150 | \input{diary/connect.dia} |
90 | the global transfer and {\tt evstr} evaluates numerically | 151 | |
91 | the global transfer function once the systems are given ``values'', i.e. | 152 | The above session is a bit long but illustrates some very important |
92 | are defined as Scilab linear systems. | 153 | aspects of the handling of linear systems. First, two linear systems |
93 | % | 154 | are created in transfer function form using the function called |
155 | {\tt syslin}\index{linear systems!{\tt syslin}}\index{syslin@{\tt syslin}}. | ||
156 | This function was used to label the systems in this example | ||
157 | as being continuous (as opposed to discrete). | ||
158 | The primitive {\tt tf2ss} is used to convert one of the | ||
159 | two transfer functions to its equivalent state-space representation | ||
160 | which is in list form (note that the function {\tt ssprint} creates a more | ||
161 | readable format for the state-space linear system). | ||
162 | The following multiplication of the two systems yields their | ||
163 | series inter-connection. Notice that the inter-connection | ||
164 | of the two systems is effected even though one of the systems is | ||
165 | in state-space form and the other is in transfer function form. | ||
166 | The resulting inter-connection is given in state-space form. | ||
167 | Finally, the function {\tt ss2tf} is used to convert the resulting | ||
168 | inter-connected systems to the equivalent transfer function representation. | ||
169 | |||
170 | |||
171 | \chapter{A Maple to Scilab Interface} | ||
172 | To combine symbolic computation of the computer algebra system Maple with the | ||
173 | numerical facilities | ||
174 | of Scilab, Maple objects can be transformed into Scilab functions. To assure | ||
175 | efficient numerical evaluation this is done through numerical evaluation in | ||
176 | Fortran. The whole process is done by a Maple procedure called | ||
177 | \verb/maple2scilab/. | ||
178 | \section{Maple2scilab} | ||
179 | \index{maple2scilab@{\tt maple2scilab}} | ||
180 | The procedure \verb!maple2scilab! converts a Maple object, | ||
181 | either a scalar function or a matrix into a Fortran subroutine | ||
182 | and writes the associated Scilab function. The code of \verb!maple2scilab! | ||
183 | is in the directory \verb!SCIDIR/maple!. | ||
184 | |||
185 | The calling sequence of \verb!maple2scilab! is as follows:\\ | ||
186 | \verb!maple2scilab(function-name,object,args)! | ||
187 | \begin{itemize} | ||
188 | \item | ||
189 | The first argument, \verb!function-name! is a name indicating the | ||
190 | function-name in Scilab. | ||
191 | \item | ||
192 | The second argument \verb!object! is the Maple name of the expression | ||
193 | to be transferred to Scilab. | ||
194 | \item | ||
195 | The third argument is a list of arguments containing the formal parameters of | ||
196 | the Maple-object \verb!object!. | ||
197 | \end{itemize} | ||
198 | When \verb!maple2scilab! is invoked in Maple, two files are generated, | ||
199 | one which contains the Fortran code and another which contains the | ||
200 | associated Scilab function. Aside their existence, the user has not to | ||
201 | know about their contents. | ||
202 | |||
203 | The Fortran routine which is generated has the following calling sequence:\\ | ||
204 | {\tt <Scilab-name>(x1,x2,\ldots,xn,matrix)} \\ | ||
205 | and this subroutine computes matrix(i,j) as a function of | ||
206 | the arguments {\tt x1,x2,\ldots,xn}. | ||
207 | Each argument can be a Maple scalar or array which should be | ||
208 | in the argument list. | ||
209 | The Fortran subroutine is put into a file named {\tt <Scilab-name>.f}, the | ||
210 | Scilab-function into a file named {\tt <Scilab-name>.sci}. | ||
211 | For numerical evaluation in Scilab the user has to compile the Fortran | ||
212 | subroutine, to link it with Scilab (e.g. Menu-bar option '\verb!link!') | ||
213 | and to load the associated function (Menu-bar option '\verb!getf!'). | ||
214 | Information about \verb!link! operation is given in Scilab's manual: | ||
215 | Fortran routines can be incorporated into Scilab by dynamic | ||
216 | link or through the \verb!Ex-fort.f! file in the \verb!default! directory. | ||
217 | Of course, this two-step procedure can be automatized using a shell-script | ||
218 | (or using \verb!unix! in Scilab). | ||
219 | Maple2scilab uses the ``Macrofort'' library which is in the share | ||
220 | library of Maple. | ||
221 | \subsection{Simple Scalar Example} | ||
222 | \paragraph{Maple-Session} | ||
94 | \begin{verbatim} | 223 | \begin{verbatim} |
224 | > read(`maple2scilab.maple`): | ||
225 | > f:=b+a*sin(x); | ||
226 | |||
227 | f := b + a sin(x) | ||
228 | |||
229 | > maple2scilab('f_m',f,[x,a,b]); | ||
230 | \end{verbatim} | ||
231 | Here the Maple variable \verb!f! is a scalar expression but it could be also | ||
232 | a Maple vector or matrix. | ||
233 | \verb/ 'f_m'/ will be the name of \verb!f! in Scilab | ||
234 | (note that the Scilab name is restricted to contain at most 6 characters). | ||
235 | The procedure \verb/maple2scilab/ creates two files: \verb/f_m.f/ | ||
236 | and \verb/f_m.sci/ in the directory where Maple is started. | ||
237 | To specify another directory just define in Maple the path : | ||
238 | \verb/rpath:=`//\verb/work//` ; then all files are written in | ||
239 | the sub-directory \verb/work/. | ||
240 | The file \verb!f_m.f! contains the source code of a stand alone Fortran | ||
241 | routine which is dynamically linked to Scilab by the function \verb!f_m! in | ||
242 | defined in the file \verb!f_m.sci!. | ||
243 | |||
244 | \paragraph{Scilab Session} | ||
245 | \begin{verbatim} | ||
246 | -->unix('make f_m.o'); | ||
95 | 247 | ||
96 | -->model=2;reg=3;proc=4;sensor=5;ff=6;somm=7; | 248 | -->link('f_m.o','f_m'); |
97 | 249 | ||
98 | -->tm=list('transfer','model');tr=list('transfer',['reg(:,1)','reg(:,2)']); | 250 | linking _f_m_ defined in f_m.o |
99 | |||
100 | -->tp=list('transfer','proc');ts=list('transfer','s | ||
101 | ensor'); | ||
102 | |||
103 | -->tf=list('transfer','ff');tsum=list('transfer',['1','1']); | ||
104 | |||
105 | -->lum=list('link','input',[-1],[model,1],[ff,1]); | ||
106 | |||
107 | -->lmr=list('link','model output',[model,1],[reg,1]); | ||
108 | |||
109 | -->lrs=list('link','regulator output',[reg,1],[somm,1]); | ||
110 | |||
111 | -->lfs=list('link','feed-forward output',[ff,1],[somm,2]); | ||
112 | |||
113 | -->lsp=list('link','proc input',[somm,1],[proc,1],[-2]); | ||
114 | |||
115 | -->lpy=list('link','proc output',[proc,1],[sensor,1],[-1]); | ||
116 | |||
117 | -->lsup=list('link','sensor output',[sensor,1],[reg,2]); | ||
118 | |||
119 | -->syst=... | ||
120 | list('blocd',tm,tr,tp,ts,tf,tsum,lum,lmr,lrs,lfs,lsp,lpy,lsup); | ||
121 | |||
122 | -->[sysf,names]=bloc2exp(syst) | ||
123 | names = | ||
124 | |||
125 | |||
126 | names>1 | ||
127 | |||
128 | input | ||
129 | 251 | ||
130 | names>2 | 252 | -->getf('f_m.sci','c') |
131 | 253 | ||
132 | !proc output ! | 254 | -->f_m(%pi,1,2) |
133 | ! ! | 255 | ans = |
134 | !proc input ! | ||
135 | sysf = | ||
136 | 256 | ||
137 | !proc*((eye()-reg(:,2)*sensor*proc)\(-(-ff-reg(:,1)*model))) ! | 257 | 2. |
138 | ! ! | ||
139 | !(eye()-reg(:,2)*sensor*proc)\(-(-ff-reg(:,1)*model)) ! | ||
140 | \end{verbatim} | 258 | \end{verbatim} |
141 | % | 259 | |
142 | Note that the argument to {\tt bloc2exp} is a list of lists. The | 260 | \subsection{Matrix Example} |
143 | first element of the list {\tt syst} is (actually) the character string | 261 | This is an example of transferring a Maple matrix into Scilab. |
144 | {\tt 'blocd'} which indicates that the list represents a block-diagram | 262 | \paragraph{Maple Session} |
145 | inter-connection of systems. Each list entry in the list {\tt syst} | ||
146 | represents a block or an inter-connection in Figure~\ref{fa.1}. | ||
147 | The form of a list which represents a block begins with a character | ||
148 | string {\tt 'transfer'} followed by a matrix of character strings | ||
149 | which gives the symbolic name of the block. If the block is multi-input | ||
150 | multi-output the matrix of character strings must be represented as | ||
151 | is illustrated by the block {\tt Reg}. | ||
152 | |||
153 | The inter-connections between blocks is also represented by lists. | ||
154 | The first element of the list is the character string {\tt 'link'}. | ||
155 | The second element of the inter-connection is its symbolic name. | ||
156 | The third element of the inter-connection is the input to the connection. | ||
157 | The remaining elements are all the outputs of the connection. | ||
158 | Each input and output to an inter-connection is a vector which | ||
159 | contains as its first element the block number (for instance the {\tt model} | ||
160 | block is assigned the number $2$). The second element of the vector | ||
161 | is the port number for the block (for the case of multi-input multi-output | ||
162 | blocks). If an inter-connection is not attached to anything the value | ||
163 | of the block number is negative (as for example the inter-connection | ||
164 | labeled {\tt 'input'} or is omitted. | ||
165 | |||
166 | The result of the {\tt bloc2exp} function is a list of names | ||
167 | which give the unassigned inputs and outputs of the system and | ||
168 | the symbolic transfer function of the system given by {\tt sysf}. | ||
169 | The symbolic names in {\tt sysf} can be associated to polynomials | ||
170 | and evaluated using the function {\tt evstr}. This is illustrated in the | ||
171 | following Scilab session. | ||
172 | % | ||
173 | \begin{verbatim} | 263 | \begin{verbatim} |
174 | 264 | > with(linalg):read(`maple2scilab.maple`): | |
175 | -->s=poly(0,'s');ff=1;sensor=1;model=1;proc=s/(s^2+3*s+2); | 265 | |
176 | 266 | > x:=vector(2):par:=vector(2): | |
177 | -->reg=[1/s 1/s];sys=evstr(sysf) | 267 | |
178 | sys = | 268 | > mat:=matrix(2,2,[x[1]^2+par[1],x[1]*x[2],par[2],x[2]]); |
179 | 269 | ||
180 | ! 1 + s ! | 270 | [ 2 ] |
181 | ! ---------- ! | 271 | [ x[1] + par[1] x[1] x[2] ] |
182 | ! 2 ! | 272 | mat := [ ] |
183 | ! 1 + 3s + s ! | 273 | [ par[2] x[2] ] |
184 | ! ! | 274 | |
185 | ! 2 3 ! | 275 | > maple2scilab('mat',mat,[x,par]); |
186 | ! 2 + 5s + 4s + s ! | ||
187 | ! ---------------- ! | ||
188 | ! 2 3 ! | ||
189 | ! s + 3s + s ! | ||
190 | 276 | ||
191 | \end{verbatim} | 277 | \end{verbatim} |
192 | % | 278 | |
193 | The resulting polynomial transfer function links the input | 279 | \paragraph{Scilab Session} |
194 | of the block system to the two outputs. Note that the output | ||
195 | of {\tt evstr} is the rational polynomial matrix {\tt sys} | ||
196 | whereas the output of {\tt bloc2exp} is a matrix of character strings. | ||
197 | |||
198 | The symbolic evaluation which is given here is not very efficient | ||
199 | with large interconnected systems. The function {\tt bloc2ss} | ||
200 | performs the previous calculation in state-space format. | ||
201 | Each system is given now in state-space | ||
202 | as a {\tt syslin} list or simply as a gain (constant matrix). | ||
203 | Note {\tt bloc2ss} performs the necessary conversions if this | ||
204 | is not done by the user. Each system must be given a value before | ||
205 | bloc2ss is called. All the calculations are made in state-space | ||
206 | representation even if the linear systems are given in transfer form. | ||
207 | |||
208 | \chapter{Converting Scilab functions to Fortran} | ||
209 | |||
210 | \section{Converting Scilab Functions to Fortran Routines} | ||
211 | |||
212 | Scilab provides a compiler (under development) to transform some Scilab | ||
213 | functions | ||
214 | into Fortran subroutines. The routines which are thus obtained | ||
215 | make use of the routines which are in the Fortran libraries. | ||
216 | All the basic matrix operations are available. | ||
217 | |||
218 | Let us consider the following Scilab function: | ||
219 | \begin{verbatim} | 280 | \begin{verbatim} |
281 | -->unix('make mat.o'); | ||
282 | |||
283 | -->link('mat.o','mat') | ||
220 | 284 | ||
221 | function [x]=macr(a,b,n) | 285 | linking _mat_ defined in mat.o |
222 | z=n+m+n, | 286 | |
223 | c(1,1)=z, | 287 | -->getf('mat.sci','c') |
224 | c(2,1)=z+1, | ||
225 | c(1,2)=2, | ||
226 | c(2,2)=0, | ||
227 | if n=1 then, | ||
228 | x=a+b+a, | ||
229 | else, | ||
230 | x=a+b-a'+b, | ||
231 | end, | ||
232 | y=a(3,z+1)-x(z,5), | ||
233 | x=2*x*x*2.21, | ||
234 | sel=1:5, | ||
235 | t=a*b, | ||
236 | for k=1:n, | ||
237 | z1=z*a(k+1,k)+3, | ||
238 | end, | ||
239 | t(sel,5)=a(2:4,7), | ||
240 | x=[a b;-b' a'] | ||
241 | 288 | ||
289 | -->par=[50;60];x=[1;2]; | ||
290 | |||
291 | -->mat(x,par) | ||
292 | ans = | ||
293 | |||
294 | ! 51. 2. ! | ||
295 | ! 60. 2. ! | ||
296 | |||
242 | \end{verbatim} | 297 | \end{verbatim} |
243 | 298 | ||
244 | which can be translated into Fortran by using the function {\tt mac2for}. | 299 | {\small |
245 | Each input parameter of the subroutine is described by a list | 300 | \paragraph{Generated code} |
246 | which contains its type and its dimensions. Here, we have three | 301 | Below is the code (Fortran subroutines and Scilab functions) which is |
247 | input variables {\tt a,b,c} which are, say, {\tt | 302 | automatically generated by {\tt maple2scilab} in the two preceding examples. |
248 | double precision, double precision, integer} with dimensions | 303 | \paragraph{Fortran routines} |
249 | {\tt (m,m), (m,m), (1,1)}. This information is gathered | ||
250 | in the following list: | ||
251 | \begin{verbatim} | 304 | \begin{verbatim} |
252 | l=list(); | 305 | c |
253 | l(1)=list('1','m','m'); | 306 | c SUBROUTINE f_m |
254 | l(2)=list('1','m','m'); | 307 | c |
255 | l(3)=list('0','1','1'); | 308 | subroutine f_m(x,a,b,fmat) |
309 | doubleprecision x,a,b | ||
310 | implicit doubleprecision (t) | ||
311 | doubleprecision fmat(1,1) | ||
312 | fmat(1,1) = b+a*sin(x) | ||
313 | end | ||
256 | \end{verbatim} | 314 | \end{verbatim} |
257 | The call to {\tt mac2for} is made as follows: | ||
258 | \begin{verbatim} | 315 | \begin{verbatim} |
259 | comp(macr); | 316 | c |
260 | mac2for(macr2lst(macr),l) | 317 | c SUBROUTINE mat |
318 | c | ||
319 | subroutine mat(x,par,fmat) | ||
320 | doubleprecision x,par(2) | ||
321 | implicit doubleprecision (t) | ||
322 | doubleprecision fmat(2,2) | ||
323 | t2 = x(1)**2 | ||
324 | fmat(2,2) = x(2) | ||
325 | fmat(2,1) = par(2) | ||
326 | fmat(1,2) = x(1)*x(2) | ||
327 | fmat(1,1) = t2+par(1) | ||
328 | end | ||
261 | \end{verbatim} | 329 | \end{verbatim} |
262 | The output of this command is a string containing a stand-alone Fortran | 330 | \paragraph{Scilab functions} |
263 | subroutine. | ||
264 | \begin{verbatim} | 331 | \begin{verbatim} |
265 | subroutine macr(a,b,n,x,m,work,iwork) | 332 | function [var]=f_m(x,a,b) |
266 | c! | 333 | var=call('f_m',x,1,'d',a,2,'d',b,3,'d','out',[1,1],4,'d') |
267 | c automatic translation | 334 | \end{verbatim} |
268 | . | 335 | \begin{verbatim} |
269 | . | 336 | function [var]=fmat(x,par) |
270 | . | 337 | var=call('fmat',x,1,'d',par,2,'d','out',[2,2],3,'d') |
271 | double precision a(m,m),b(m,m),x(m+m,m+m),y,z1,24(m,m),work(*) | 338 | \end{verbatim} |
272 | integer n,m,z,c(2,2),sel(5),k,iwork(*) | 339 | } |
273 | . | ||
274 | . | ||
275 | . | ||
276 | call dmcopy(b,m,x(1,m+1),m+m,m,m) | ||
277 | call dmcopy(work(iw1),m,x(m+1,1),m+m,m,m) | ||
278 | call dmcopy(work(iw1),m,x(m+1,m+1),m+m,m,m) | ||
279 | return | ||
280 | c | ||
281 | end | ||
282 | 340 | ||
341 | \subsection{The {\tt addinter} command} | ||
342 | Once the interface program is written, it must be compiled to produce | ||
343 | an object file. It is then linked to Scilab by the addinter command. | ||
344 | |||
345 | The syntax of addinter is the following: | ||
346 | |||
347 | {\tt addinter([`interface.o', 'userfiles.o'],'entrypt',['scifcts'])} | ||
348 | |||
349 | Here {\tt interface.o} is the object file of the interface, | ||
350 | {\tt userfiles.o} is the set of user's routines to be linked, | ||
351 | {\tt entrypt} is the entry point of the interface routine and | ||
352 | {'scifcts'} is the set of Scilab functions to be interfaced. | ||
283 | 353 | ||
284 | \end{verbatim} | ||
285 | This routine can be linked to Scilab and interactively called. | ||
286 | 354 | ||
diff --git a/scilab_doc/intro/chap0.tex b/scilab_doc/intro/chap0.tex index 139e31b..0e9182d 100755 --- a/scilab_doc/intro/chap0.tex +++ b/scilab_doc/intro/chap0.tex | |||
@@ -3,19 +3,19 @@ | |||
3 | \pagestyle{empty} | 3 | \pagestyle{empty} |
4 | 4 | ||
5 | 5 | ||
6 | \hspace*{-2.cm} | 6 | %\hspace*{-2.cm} |
7 | . | 7 | %. |
8 | %BEGIN IMAGE | 8 | %BEGIN IMAGE |
9 | \fbox{\hspace*{0.cm} \begin{picture}(500.0,680.0) | 9 | %\fbox{\hspace*{0.cm} \begin{picture}(500.0,680.0) |
10 | \vspace{-3.cm} | 10 | %\vspace{-3.cm} |
11 | \special{psfile=intro.couv1} | 11 | %\special{psfile=intro.couv1} |
12 | \hspace*{-2.cm} | 12 | %\hspace*{-2.cm} |
13 | \special{psfile=intro.couv2} | 13 | %\special{psfile=intro.couv2} |
14 | \end{picture}} | 14 | %\end{picture}} |
15 | %END IMAGE | 15 | %END IMAGE |
16 | %HEVEA\imageflush | 16 | %HEVEA\imageflush |
17 | 17 | ||
18 | \newpage | 18 | %\newpage |
19 | \vspace{8.cm} | 19 | \vspace{8.cm} |
20 | 20 | ||
21 | {\Huge\bf {INTRODUCTION}} | 21 | {\Huge\bf {INTRODUCTION}} |
@@ -32,22 +32,24 @@ | |||
32 | 32 | ||
33 | \vspace{3.cm} | 33 | \vspace{3.cm} |
34 | 34 | ||
35 | {\Huge\bf {Scilab Group}} | 35 | %{\Huge\bf {Scilab Research Core Team}} |
36 | 36 | ||
37 | {\Large\bf | 37 | {\Large\bf |
38 | INRIA Meta2 Project/ENPC Cergrene} | 38 | INRIA/ENPC} |
39 | 39 | ||
40 | {\normalsize\bf | 40 | {\normalsize\bf |
41 | 41 | ||
42 | \vspace{12.cm} | 42 | \vspace{12.cm} |
43 | 43 | ||
44 | INRIA - Unit\'e de recherche de Rocquencourt - Projet Meta2 | 44 | INRIA - Rocquencourt unit - Metalau project. |
45 | 45 | ||
46 | Domaine de Voluceau - Rocquencourt - B.P. 105 - 78153 Le Chesnay Cedex (France) | 46 | Domaine de Voluceau - Rocquencourt - B.P. 105 - 78153 Le Chesnay Cedex (France) |
47 | 47 | ||
48 | ENPC - Cit\'e Descartes -Champs sur Marne- 77455 Marne la Vall\'ee Cedex (France) | ||
49 | |||
48 | E-mail : scilab@inria.fr} | 50 | E-mail : scilab@inria.fr} |
49 | 51 | ||
50 | {\normalsize\bf Home page : http://www-rocq.inria.fr/scilab} | 52 | {\normalsize\bf Home page : \href{http://www.scilab.org}{www.scilab.org}} |
51 | 53 | ||
52 | \newpage | 54 | \newpage |
53 | \mbox{ } | 55 | \mbox{ } |