11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# Copyright (c) P.J.Gawthrop 1991, 1992, 1994.
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.10 1998/11/18 13:50:29 peterg
## Removed writeing of EYz matrix
##
## Revision 1.9 1998/11/18 10:53:38 peterg
## Put in some more "IF MTTNx>0 THEN" to avoid error messages when no
## states.
##
|
>
>
>
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# Copyright (c) P.J.Gawthrop 1991, 1992, 1994.
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.11 1998/11/26 09:18:55 peterg
## Incluse subs.r
##
## Revision 1.10 1998/11/18 13:50:29 peterg
## Removed writeing of EYz matrix
##
## Revision 1.9 1998/11/18 10:53:38 peterg
## Put in some more "IF MTTNx>0 THEN" to avoid error messages when no
## states.
##
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
## Sorted out bug when MTTNz=0
##
## Revision 1.1 1996/08/15 16:47:02 peter
## Initial revision
##
###############################################################
#Explicit solution option
solve=0
while [ -n "`echo $1 | grep '^-'`" ]; do
case $1 in
-A )
solve=1;;
*)
echo "$1 is an invalid argument - ignoring" ;;
esac
shift
done
if [ "$solve" = "1" ]; then
echo "Creating $1_cse.r (with explicit solution of algebraic equations)"
else
|
|
>
>
|
|
|
|
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
## Sorted out bug when MTTNz=0
##
## Revision 1.1 1996/08/15 16:47:02 peter
## Initial revision
##
###############################################################
# Create the reduce output code
def2write_r $1 cse
def2write_r $1 cseo
#Explicit solution option
solve=0
while [ -n "`echo $1 | grep '^-'`" ]; do
case $1 in
-A )
solve=1;;
*)
echo "$1 is an invalid argument - ignoring" ;;
esac
shift
done
if [ "$solve" = "1" ]; then
echo "Creating $1_cse.r (with explicit solution of algebraic equations)"
else
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
%Create list of the relevant unknowns
MTT_unknowns := {};
FOR i := 1:MTTNyz DO
MTT_unknowns := append(MTT_unknowns,{MTTUi(i,1)});
%Solve the algebraic equations symbolically
MTT_sol := solve(MTT_eqns,MTT_unknowns);
%The result seems to be in an extra list - I don't know why
% So remove the outer list with first.
% But only if more than one list element!
if MTTNyz>1 THEN
MTT_sol := first(MTT_sol);
%Substitute back into the equations
FOR i := 1:MTTNyz DO
BEGIN
MTT_sol_i := first(MTT_sol); MTT_sol := rest(MTT_sol);
set(lhs(MTT_sol_i),rhs(MTT_sol_i));
END;
% No algebraic variables left!
MTTNYz := 0;
END; % IF MTTNyz>0
%%Create the _cse.r file
OUT "$1_cse.r";
% State derivative
MTT_Matrix := MTTEdX$
MTT_Matrix_name := "MTTEdX"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := 1$
Reduce_Matrix()$
% Output
MTT_Matrix := MTTY$
MTT_Matrix_name := "MTTY"$
MTT_Matrix_n := MTTNy$
MTT_Matrix_m := 1$
Reduce_Matrix()$
% Inputs
MTT_Matrix := MTTU$
MTT_Matrix_name := "MTTU"$
MTT_Matrix_n := MTTNu$
MTT_Matrix_m := 1$
Reduce_Matrix()$
MTT_Matrix := MTTdU$
MTT_Matrix_name := "MTTdU"$
MTT_Matrix_n := MTTNu$
MTT_Matrix_m := 1$
Reduce_Matrix()$
% E matrix
MTT_Matrix := MTTE$
MTT_Matrix_name := "MTTE"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$
% Eyx matrix
MTT_Matrix := MTTEyx$
MTT_Matrix_name := "MTTEyx"$
MTT_Matrix_n := MTTNy$
MTT_Matrix_m := MTTNx$
%Reduce_Matrix()$
% Yz
MTT_Matrix := MTTYz$
MTT_Matrix_name := "MTTYz"$
MTT_Matrix_n := MTTNyz$
MTT_Matrix_m := 1$
Reduce_Matrix()$
write ";END;";
SHUT "$1_cse.r";
quit;
EOF
if [ "$solve" = "1" ]; then
echo "Setting MTTNyz=0 in $1_def.r and removing other $1_def files"
awk '{
if ($1=="MTTNyz")
print "MTTNyz := 0;"
else print $0
}' $1_def.r > mtt_junk
|
|
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
>
>
>
>
>
>
>
>
>
>
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
%Create list of the relevant unknowns
MTT_unknowns := {};
FOR i := 1:MTTNyz DO
MTT_unknowns := append(MTT_unknowns,{MTTUi(i,1)});
%Solve the algebraic equations symbolically
MTT_sol := solve(MTT_eqns,MTT_unknowns);
%The result seems to be in an extra list - I dont know why
% So remove the outer list with first.
% But only if more than one list element!
if MTTNyz>1 THEN
MTT_sol := first(MTT_sol);
%Substitute back into the equations
FOR i := 1:MTTNyz DO
BEGIN
MTT_sol_i := first(MTT_sol); MTT_sol := rest(MTT_sol);
set(lhs(MTT_sol_i),rhs(MTT_sol_i));
END;
% No algebraic variables left!
MTTNYz := 0;
END; % IF MTTNyz>0
% Create the matrix declarations
OUT "$1_cse.r1";
write "MATRIX MTTEdx(", MTTNx, ",", 1, ")$";
write "MATRIX MTTE(", MTTNx, ",", MTTNx, ")$";
SHUT "$1_cse.r1";
OUT "$1_cseo.r1";
write "MATRIX MTTY(", MTTNy, ",", MTTNx, ")$";
SHUT "$1_cseo.r1";
%%Create the _cse.r file
OUT "$1_cse.r2";
write "%File: $1_cse.r";
in ("$1_cse_write.r");
write "in ""$1_cseo.r"";";
write "END;";
% % State derivative
% MTT_Matrix := MTTEdX$
% MTT_Matrix_name := "MTTEdX"$
% MTT_Matrix_n := MTTNx$
% MTT_Matrix_m := 1$
% Reduce_Matrix()$
% % Output
% MTT_Matrix := MTTY$
% MTT_Matrix_name := "MTTY"$
% MTT_Matrix_n := MTTNy$
% MTT_Matrix_m := 1$
% Reduce_Matrix()$
% % Inputs
% MTT_Matrix := MTTU$
% MTT_Matrix_name := "MTTU"$
% MTT_Matrix_n := MTTNu$
% MTT_Matrix_m := 1$
% Reduce_Matrix()$
% MTT_Matrix := MTTdU$
% MTT_Matrix_name := "MTTdU"$
% MTT_Matrix_n := MTTNu$
% MTT_Matrix_m := 1$
% Reduce_Matrix()$
% % E matrix
% MTT_Matrix := MTTE$
% MTT_Matrix_name := "MTTE"$
% MTT_Matrix_n := MTTNx$
% MTT_Matrix_m := MTTNx$
% Reduce_Matrix()$
% % Eyx matrix
% MTT_Matrix := MTTEyx$
% MTT_Matrix_name := "MTTEyx"$
% MTT_Matrix_n := MTTNy$
% MTT_Matrix_m := MTTNx$
% %Reduce_Matrix()$
% % Yz
% MTT_Matrix := MTTYz$
% MTT_Matrix_name := "MTTYz"$
% MTT_Matrix_n := MTTNyz$
% MTT_Matrix_m := 1$
% Reduce_Matrix()$
write ";END;";
SHUT "$1_cse.r2";
%Write out the output equations
OUT "$1_cseo.r2";
write "%File: $1_cseo.r";
in ("$1_cseo_write.r");
write "END;";
SHUT "$1_cseo.r2";
quit;
EOF
cat $1_cse.r1 $1_cse.r2 > $1_cse.r
cat $1_cseo.r1 $1_cseo.r2 > $1_cseo.r
if [ "$solve" = "1" ]; then
echo "Setting MTTNyz=0 in $1_def.r and removing other $1_def files"
awk '{
if ($1=="MTTNyz")
print "MTTNyz := 0;"
else print $0
}' $1_def.r > mtt_junk
|