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
169
|
MTTt = 0.0;
[MTTu] = zero_input($Nu); # Zero the input
[MTTx] = $1_state; # Read in initial state
[MTTy] = $1_odeo(MTTx,MTTu,MTTt); # Evaluate initial output
[MTTu] = $1_input(MTTt,MTTx,MTTy); # Evaluate initial input
mtt_write(MTTt,MTTx,MTTy,$Nx,$Ny); # And write them
#[mttAA] = zero_matrix($Nx); # Zero the A matrix
#[mttAAx] = zero_vector($Nx); # Zero the AAx vector
#if $Nx>0
# [MTTx] = $1_switch(MTTx); # Switches
#endif;
if mttmethod==1 # Euler
MTTddt = mttdt/mttstepfactor; # The small sample interval
endif;
for MTTit = 1:MTTilast #Integration loop
if $Nx>0 # Dont if no states
if mttmethod==1 # Euler
for MTTjt = 1:mttstepfactor
[MTTdx] = $1_ode(MTTx,MTTu,MTTt); # State derivative
[MTTopen] = $1_switchopen(MTTx); # Open switches
[MTTx] = mtt_euler(MTTx,MTTdx,MTTddt,$Nx,MTTopen); # Euler update
MTTt = MTTt + MTTddt;
endfor;
endif;
if mttmethod==2 # Implicit
[MTTdx] = $1_ode(MTTx,MTTu,MTTt); # State derivative
[mttAA,mttAAx] = $1_smx(MTTx,MTTu,mttdt); # (I-Adt) and (I-Adt)x
[MTTopen] = $1_switchopen(MTTx); # Open switches
[MTTx] = mtt_implicit(MTTx,MTTdx,mttAA,mttAAx,mttdt,$Nx,MTTopen); # Implicit update
MTTt = MTTt + mttdt;
endif;
else
MTTt = MTTt + mttdt;
endif; # $Nx>0
[MTTy] = $1_odeo(MTTx,MTTu,MTTt); # Output
[MTTu] = $1_input(MTTt,MTTx,MTTy); # Input
mtt_write(MTTt,MTTx,MTTy,$Nx,$Ny); # Write it out
endfor; # Integration loop
EOF
|
|
>
|
>
>
|
>
|
>
>
>
>
>
|
|
|
>
>
>
>
>
|
|
|
>
>
|
>
>
|
|
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
MTTt = 0.0;
[MTTu] = zero_input($Nu); # Zero the input
[MTTx] = $1_state; # Read in initial state
[MTTy] = $1_$odeo(MTTx,MTTu,MTTt); # Evaluate initial output
[MTTu] = $1_input(MTTt,MTTx,MTTy); # Evaluate initial input
mtt_write(MTTt,MTTx,MTTy,$Nx,$Ny); # And write them
#[mttAA] = zero_matrix($Nx); # Zero the A matrix
#[mttAAx] = zero_vector($Nx); # Zero the AAx vector
#if $Nx>0
# [MTTx] = $1_switch(MTTx); # Switches
#endif;
EOF
if [ "$method" = "euler" ]; then
cat << EOF >> $1_ode2odes.m
MTTddt = mttdt/mttstepfactor; # The small sample interval
EOF
fi
cat << EOF >> $1_ode2odes.m
for MTTit = 1:MTTilast #Integration loop
if $Nx>0 # Dont if no states
EOF
if [ "$method" = "euler" ]; then
cat << EOF >> $1_ode2odes.m
# if mttmethod==1 # Euler
for MTTjt = 1:mttstepfactor
[MTTdx] = $1_$ode(MTTx,MTTu,MTTt); # State derivative
[MTTopen] = $1_switchopen(MTTx); # Open switches
[MTTx] = mtt_euler(MTTx,MTTdx,MTTddt,$Nx,MTTopen); # Euler update
MTTt = MTTt + MTTddt;
endfor;
# endif;
EOF
fi
if [ "$method" = "implicit" ]; then
cat << EOF >> $1_ode2odes.m
# if mttmethod==2 # Implicit
[MTTdx] = $1_cse(MTTx,MTTu,MTTt); # State derivative
[mttAA,mttAAx] = $1_smx(MTTx,MTTu,mttdt); # (I-Adt) and (I-Adt)x
[MTTopen] = $1_switchopen(MTTx); # Open switches
[MTTx] = mtt_implicit(MTTx,MTTdx,mttAA,mttAAx,mttdt,$Nx,MTTopen); # Implicit update
MTTt = MTTt + mttdt;
# endif;
EOF
fi
cat << EOF >> $1_ode2odes.m
else # NX is 0 - no states
MTTt = MTTt + mttdt;
endif; # $Nx>0
[MTTy] = $1_$odeo(MTTx,MTTu,MTTt); # Output
[MTTu] = $1_input(MTTt,MTTx,MTTy); # Input
mtt_write(MTTt,MTTx,MTTy,$Nx,$Ny); # Write it out
endfor; # Integration loop
EOF
|