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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
-
-
+
+
+
+
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
if nargin<3
i_par = []
else
i_par = ppp_indices (par_names,sympar,sympars); # Parameters
endif
if extras.visual # Do some simulations
## Do some simulations to check things out
## System itself
par = ${sys}_numpar;
x_0_ol = ${sys}_state(par);
[y_ol,x_ol, t_ol] = ${sys}_sim(x_0_ol, par, simpar, ones(1,n_u));
simpar_OL = simpar;
simpar_OL.last = simpars.last;
[y_OL,x_OL, t_OL] = ${sys}_sim(x_0_ol, par, simpar_OL, ones(1,n_u));
pars = s${sys}_numpar;
x_0_ppp = s${sys}_state(pars);
[y_ppp,y_par,x_ppp, t_ppp] = s${sys}_ssim(x_0_ppp, pars, simpars, ones(1,n_u));
simpar_PPP = simpars;
simpar_PPP.first = simpar.first;
[y_PPP,y_par,x_PPP, t_PPP] = s${sys}_ssim(x_0_ppp, pars, simpar_PPP, ones(1,n_u));
## Basis functions
Us = ppp_ustar(A_u,1,t_OL',0,0)';
if extras.visual #Show some graphs
figure(2);
grid; title("Outputs of ${sys}_sim and s${sys}_ssim");
plot(t_ol,y_ol, '*', t_ppp, y_ppp, '+', t_OL, y_OL, t_PPP, y_PPP);
## Basis functions
Us = ppp_ustar(A_u,1,t_OL',0,0)';
figure(3);
grid; title("Basis functions");
plot(t_OL, Us);
endif
## Do it
[y,u,t,p,U,t_open,t_ppp,t_est,its_ppp,its_est] \
[y,u,t,P,U,t_open,t_ppp,t_est,its_ppp,its_est] \
= ppp_nlin_run ("${sys}",i_ppp,i_par,A_u,w_s,N,Q,extras);
## Compute values at ends of ol intervals
T_open = cumsum(t_open);
T_open = T_open(1:length(T_open)-1); # Last point not in t
j=[];
for i = 1:length(T_open)
j = [j; find(T_open(i)*ones(size(t))==t)];
endfor
y_open = y(j,:);
u_open = u(j,:);
## Plots
gset nokey
gset nogrid
gset format x "%i"
gset format x "%4.1f"
gset format y "%4.1f"
gset term fig monochrome portrait fontsize 20 size 20 20 metric \
thickness 4
gset output "${sys}_nppp.fig"
title("");
grid;
xlabel("Time (s)");
ylabel("u");
subplot(2,1,2); plot(t,u,'-', T_open, u_open,"^");
grid;
ylabel("y");
subplot(2,1,1); plot(t,y,'-', T_open, y_open,"^");
oneplot;
gset output "${sys}_nppp.basis.fig"
title("");
xlabel("Time (s)");
ylabel("Basis functions");
plot(t_OL, Us);
## Create plot against time
TTT = [ [0;T_open] [T_open; last] ]';
TT = TTT(:);
[n,m] = size(P);
if m>0
P = P(1:n-1,:); # Loose last point
PP = [];
for j=1:m
pp = [P(:,j) P(:,j)]';
PP = [PP pp(:)];
endfor
oneplot;
gset output "${sys}_nppp.par.fig"
title("");
xlabel("Time (s)");
ylabel("Parameters");
plot(TT,PP);
endif
[n,m] = size(U);
if m>0 oneplot;
gset output "${sys}_nppp.U.fig"
title("");
xlabel("Time (s)");
ylabel("U");
[n,m] = size(U);
U = U(1:n-1,:); # Loose last point
UU = [];
for j=1:m
uu = [U(:,j) U(:,j)]';
UU = [UU uu(:)];
endfor
plot(TT,UU);
endif
endfunction
EOF
}
make_nppp_numpar() {
|