Overview
Comment:Initial revision
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 0971e8129aeaaed148ae7ab583a1be96707fab0b357056716fd689c5fae269af
User & Date: gawthrop@users.sourceforge.net on 1999-11-22 21:08:22
Other Links: branch diff | manifest | tags
Context
1999-11-22
23:01:55
Now does multiple parameters.
Output function now included.
check-in: 7c4507b23d user: gawthrop@users.sourceforge.net tags: origin/master, trunk
21:08:22
Initial revision check-in: 0971e8129a user: gawthrop@users.sourceforge.net tags: origin/master, trunk
00:23:18
Removed debugging check-in: b9523bb2d0 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Added mttroot/mtt/bin/trans/cse2scse_r version [fe7d17e66f].

















































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: cse2scse_r
# Reduce constrained-state equations to sensitivity version
# P.J.Gawthrop 10th May 199, 8th August 1991, April 1994, Dec 1994
# Copyright (c) P.J.Gawthrop, 1999


# The sensitivity parameter
theta=$2
thetas=$2"s"

echo $theta $thetas
# Number of states
Nx=`grep "MTTNx " <$1_def.r | awk '{print $3}' | sed 's/;//'`

#Inform user
echo "Creating $1_scse.r (for parameter $theta, $Nx states)"

# Remove the old log file
rm -f cse2scse_r.log

# Use reduce to accomplish the transformation
$SYMBOLIC  << EOF >cse2scse_r.log

%Read the formatting function
in "$MTTPATH/trans/reduce_matrix.r";

%Read the definitions file
in "$1_def.r";

%Read the substitution file
in "$1_subs.r";

%Read the constrained-state equations file
in "$1_cse.r";

% Compute the sensitivity E matrix
matrix MTTssE(MTTNx,MTTNx);
clear MTTx; % Dont use - mkid is better

FOR ii := 1:MTTNx DO
  FOR jj := 1:MTTNx DO
  BEGIN
    % First with respect to theta...
    MTTssE(ii,jj) := df(MTTE(ii,jj), $theta)*$thetas;
    % then with respect to x
    FOR i := 1:MTTNx DO
    BEGIN
      xi := mkid(MTTx,i);
      sxi := mkid(MTTsx,i);
      MTTssE(ii,jj) := MTTssE(ii,jj) + df(MTTE(ii,jj), xi)*sxi;
    END;
  END;

% Compute the sensitivity of the RHS of the cse
matrix MTTssEdx(MTTNx,1);


FOR ii := 1:MTTNx DO
BEGIN 
  % First with respect to theta
  MTTssEdx(ii,1) := $thetas*df(MTTEdx(ii,1), $theta);
  
% Then with respect to x
  FOR i := 1:MTTNx DO
  BEGIN
    xi := mkid(MTTx,i);
    sxi := mkid(MTTsx,i);
    MTTssEdx(ii,1) := MTTssEdx(ii,1) + df(MTTEdx(ii,1), xi)*sxi;
  END; 
END; 

% Now reorganise everything into composite system
%  - odd rows are the system 
%  - even rows are the sensitivity system
% NB at this stage, the states are numbered incorrectly - sorted out below.

%E matrix 
MTTNx2 := 2*MTTNx;
matrix MTTsE(MTTNx2,MTTNx2);
FOR i := 1:MTTNx DO
  FOR j := 1:MTTNx DO
  BEGIN
    MTTsE(2*i-1,2*j-1) := MTTE(i,j);  % System
    MTTsE(2*i,2*j)     := MTTE(i,j);  % Sensitivity system
    MTTsE(2*i,2*j-1)   := MTTssE(i,j);  % Sensitivity system
  END; 

%dX matrix
matrix MTTsEdX(MTTNx2,1);

FOR i := 1:MTTNx DO
BEGIN
  MTTsEdX(2*i-1,1) := MTTEdx(i,1);
  MTTsEdX(2*i,1)   := MTTssEdx(i,1);
END; 

OFF nat;

OUT "$1_scse.r";

write "%File: $1_scse.r";


% E matrix
MTT_Matrix := MTTsE$ 
MTT_Matrix_name := "MTTsE"$
MTT_Matrix_n := MTTNx2$
MTT_Matrix_m := MTTNx2$
Reduce_Matrix()$

% State derivative
MTT_Matrix := MTTsEdX$ 
MTT_Matrix_name := "MTTsEdX"$
MTT_Matrix_n := MTTNx2$
MTT_Matrix_m := 1$
Reduce_Matrix()$

% Output
MTT_Matrix := MTTY$ 
MTT_Matrix_name := "MTTY"$
MTT_Matrix_n := MTTNy$
MTT_Matrix_m := 1$
Reduce_Matrix()$

write "END;";

SHUT "$1_scse.r";
quit;
EOF

# Now invoke the standard error handling.
mtt_error_r cse2scse_r.log


## Now reorganise the  states
mv -f $1_scse.r mtt_junk


##echo "Nx = $Nx"
awk '{
  ## Make sure all MTTn variables are followed by a space
  gsub(/mttx[0-9]*/, "& ");

  for (i=Nx;i>0;i--) {

    state = sprintf("mttx%i ",i);
    newstate = sprintf("mttx%i ",2*i-1);
    sstate = sprintf("mttsx%i",i);
    newsstate = sprintf("mttx%i",2*i);

    gsub(state,newstate);
    gsub(sstate,newsstate);

  }
  print $0
}' Nx=$Nx <mtt_junk > $1_scse.r







MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]