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
|
[MTTx] = $1_switch(MTTx); # Switches
[MTTy] = $1_odeo(MTTx,MTTu,MTTt); # Evaluate initial output
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 mttmethod==1 #Euler
mttsteps = mttstepfactor;
endif;
if mttmethod>1 #everything else
mttsteps = 1;
end;
mttddt = mttdt/mttsteps; # The small sample interval
if mttmethod==2 #Linear implicit
mttAA = $1_smx(MTTx,MTTu,mttdt); # Set up AA= I-Adt matrix - linearised system
end;
#Integration loop
for MTTit = 1:MTTilast
if mttmethod==3 # nonlinear implicit
[mttAA] = $1_smx(MTTx,MTTu,mttdt); # Set up AA=I-A*dt matrix - linearised system
end;
if mttmethod>1 # nonlinear implicit
[mttAAx] = $1_smxx(MTTx,MTTu,MTTx,mttdt); # Set up AAx = AA*x vector - linearised system
end;
[MTTu] = $1_input(MTTx,MTTt); # Input
for MTTjt = 1:mttsteps
[MTTdx] = $1_ode(MTTx,MTTu,MTTt); # State derivative
[MTTx] = mtt_update(MTTdx,MTTx,mttAAx,mttAA,mttdt,mttstepfactor,$Nx,mttmethod);
MTTt = MTTt + mttddt;
end;
[MTTx] = $1_switch(MTTx); # Switches
[MTTy] = $1_odeo(MTTx,MTTu,MTTt);
mtt_write(MTTt,MTTx,MTTy,$Nx,$Ny);
end;
EOF
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
|
|
|
|
>
>
>
>
>
>
>
|
|
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
|
[MTTx] = $1_switch(MTTx); # Switches
[MTTy] = $1_odeo(MTTx,MTTu,MTTt); # Evaluate initial output
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 mttmethod==1 # Euler
MTTddt = mttdt/mttstepfactor; # The small sample interval
endif;
#Integration loop
for MTTit = 1:MTTilast
[MTTu] = $1_input(MTTx,MTTt); # Input
if mttmethod==1 # Euler
for MTTjt = 1:mttstepfactor
[MTTdx] = $1_ode(MTTx,MTTu,MTTt); # State derivative
[MTTx] = mtt_euler(MTTx,MTTdx,MTTddt,$Nx); # 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
[MTTx] = mtt_implicit(MTTx,MTTdx,mttAA,mttAAx,mttdt,$Nx); # Implicit update
MTTt = MTTt + mttdt;
endif;
[MTTx] = $1_switch(MTTx); # Switches
[MTTy] = $1_odeo(MTTx,MTTu,MTTt);
mtt_write(MTTt,MTTx,MTTy,$Nx,$Ny);
endfor; # Integration loop
EOF
|