Overview
Comment:Complete rewrite
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 99eaa00ae684936f0a7265a6ac49fe7aa906fd1c8503cd02d6f9ebdbdb939e8b
User & Date: gawthrop@users.sourceforge.net on 2002-05-14 15:43:41
Other Links: branch diff | manifest | tags
Context
2002-05-14
20:19:06
Fixed some memory leaks. check-in: 17f786bed8 user: geraint@users.sourceforge.net tags: origin/master, trunk
15:43:41
Complete rewrite check-in: 99eaa00ae6 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
2002-05-13
22:46:30
Plant can now have multiple inputs. check-in: faa8358236 user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/lib/rep/nppp_rep.make from [ad1e223858] to [ca75fec30a].

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
# -*-makefile-*-
# Makefile for representation nppp
# File nppp_rep.make

#Copyright (C) 2000,2001,2002 by Peter J. Gawthrop



all: $(SYS)_nppp.$(LANG)




$(SYS)_nppp.view: $(SYS)_nppp.ps
	echo Viewing $(SYS)_nppp.ps; ghostview $(SYS)_nppp.ps&

$(SYS)_nppp.ps: $(SYS)_ode2odes.out s$(SYS)_ode2odes.out \
                $(SYS)_sim.m s$(SYS)_sim.m \
                $(SYS)_state.m $(SYS)_sympar.m $(SYS)_numpar.m  \


                s$(SYS)_state.m s$(SYS)_sympar.m s$(SYS)_numpar.m \


                $(SYS)_sm.m $(SYS)_def.m  s$(SYS)_def.m \

                $(SYS)_simpar.m s$(SYS)_simpar.m
	octave $(SYS)_nppp.m




$(SYS)_ode2odes.out: 
	echo Starting creation of $(SYS)_ode2odes.out '....'


	mtt -q -stdin $(SYS) ode2odes out

s$(SYS)_ode2odes.out:

	echo Starting creation of s$(SYS)_ode2odes.out '....'
	mtt  -q -stdin -s s$(SYS) ode2odes out



$(SYS)_sim.m:
	echo Starting creation of $(SYS)_sim '....'
	mtt -q $(SYS) sim m

s$(SYS)_sim.m:
	echo Starting creation of s$(SYS)_sim. '....'
	mtt -q  -s s$(SYS) sim m

$(SYS)_state.m:
	echo Starting creation of $(SYS)_state. '....'
	mtt -q $(SYS) state m

$(SYS)_sympar.m :
	echo Starting creation of $(SYS)_sympar.m '....'
	mtt -q $(SYS) sympar m 

$(SYS)_numpar.m:

	echo Starting creation of $(SYS)_numpar. '....'
	mtt -q $(SYS) numpar m


$(SYS)_simpar.m:

	echo Starting creation of $(SYS)_simpar. '....'
	mtt -q $(SYS) simpar m


s$(SYS)_state.m:

	echo Starting creation of s$(SYS)_state. '....'
	mtt -q -s s$(SYS) state m


s$(SYS)_sympar.m :
	echo Starting creation of s$(SYS)_sympar.m '....'
	mtt -q -s s$(SYS) sympar m 

s$(SYS)_numpar.m:
	echo Starting creation of s$(SYS)_numpar. '....'
	mtt -q -s s$(SYS) numpar m

s$(SYS)_simpar.m:
	echo Starting creation of s$(SYS)_simpar. '....'
	mtt -q -s s$(SYS) simpar m

$(SYS)_sm.m:
	echo Starting creation of $(SYS)_sm. '....'
	mtt -q $(SYS) sm m

$(SYS)_def.m:
	echo Starting creation of $(SYS)_def. '....'
	mtt -q $(SYS) def m

s$(SYS)_def.m:
	echo Starting creation of s$(SYS)_def. '....'
	mtt -q -s s$(SYS) def m















>
>
|

>
>
>
|
|

|
|
|
>
>
|
>
>
|
>
|
|
>
>

>
|
|
>
>
|

|
>
|
|
>

>
|
<
|

|
<
|

|
<
|

|
<
|

|
>
|
|
>

|
>
|
|
>

|
>
|
<

>
|
<
|

|
<
|

|
<
|

|
<
|

|
<
|

|
<
|

|
>

>
>



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
# -*-makefile-*-
# Makefile for representation nppp
# File nppp_rep.make

#Copyright (C) 2000,2001,2002 by Peter J. Gawthrop

model_reps = ${SYS}_sympar.m ${SYS}_simpar.m ${SYS}_state.m\
             ${SYS}_numpar.m ${SYS}_input.m ${SYS}_ode2odes.m\
             ${SYS}_sim.m ${SYS}_def.m

sensitivity_reps = s${SYS}_sympar.m s${SYS}_simpar.m s${SYS}_state.m\
                   s${SYS}_numpar.m s${SYS}_input.m s${SYS}_ode2odes.m\
                   s${SYS}_ssim.m s${SYS}_def.m

all: ${SYS}_nppp.${LANG}

${SYS}_nppp.help_short:
	nppp_rep.sh ${SYS} help_short

${SYS}_nppp.help_long:
	nppp_rep.sh ${SYS} help_long

${SYS}_nppp.view: ${SYS}_nppp.ps
	echo Viewing ${SYS}_nppp.ps; ghostview ${SYS}_nppp.ps&

${SYS}_nppp.ps: ${SYS}_nppp.fig
	nppp_rep.sh ${SYS} ps

${SYS}_nppp.fig: ${SYS}_nppp.gdat
	nppp_rep.sh ${SYS} fig

${SYS}_nppp.gdat: ${SYS}_nppp.dat2
	nppp_rep.sh ${SYS} gdat

${SYS}_nppp.dat2: ${SYS}_nppp.m ${SYS}_nppp_numpar.m \
                  ${model_reps} ${sensitivity_reps} ${SYS}_def.r
	nppp_rep.sh ${SYS} dat2

${SYS}_nppp.m: 
	nppp_rep.sh ${SYS} m

${SYS}_nppp_numpar.m:
	nppp_rep.sh ${SYS} numpar.m

## System model reps
${SYS}_sympar.m:

	mtt ${OPTS} -q -stdin ${SYS} sympar m

${SYS}_simpar.m:

	mtt ${OPTS} -q -stdin ${SYS} simpar m

${SYS}_state.m:

	mtt ${OPTS} -q -stdin ${SYS} state m

${SYS}_numpar.m:

	mtt ${OPTS} -q -stdin ${SYS} numpar m

${SYS}_input.m:
	mtt ${OPTS} -q -stdin ${SYS} input m

${SYS}_ode2odes.m:
	mtt ${OPTS} -q -stdin ${SYS} ode2odes m

${SYS}_sim.m:
	mtt ${OPTS} -q -stdin ${SYS} sim m

${SYS}_def.m:
	mtt ${OPTS} -q -stdin ${SYS} def m

${SYS}_def.r:
	mtt ${OPTS} -q -stdin ${SYS} def r



## Sensitivity model reps
s${SYS}_sympar.m:

	mtt -q -stdin ${OPTS} -s s${SYS} sympar m

s${SYS}_simpar.m:

	mtt -q -stdin ${OPTS} -s s${SYS} simpar m

s${SYS}_state.m:

	mtt -q -stdin ${OPTS} -s s${SYS} state m

s${SYS}_numpar.m:

	mtt -q -stdin ${OPTS} -s s${SYS} numpar m

s${SYS}_input.m:

	mtt -q -stdin ${OPTS} -s s${SYS} input m

s${SYS}_ode2odes.m:

	mtt -q -stdin ${OPTS} -s s${SYS} ode2odes m

s${SYS}_ssim.m:
	mtt -q -stdin ${OPTS} -s s${SYS} ssim m

s${SYS}_def.m:
	mtt -q -stdin ${OPTS} -s s${SYS} def m



Modified mttroot/mtt/lib/rep/nppp_rep.sh from [dd3ac0c981] to [55671a0d9d].

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
#! /bin/sh

## nppp_rep.sh
## DIY representation "nppp" for mtt
# Copyright (C) 2002 by Peter J. Gawthrop

sys=$1
rep=nppp
lang=$2
mtt_parameters=$3
parameters=$4


target=${sys}_${rep}.${lang}





























## Make the _nppp.m file
make_nppp() {
filename=${sys}_${rep}.m
echo Creating ${filename}

cat > ${filename} <<EOF    
function [y,u,t] = ${sys}_nppp (last, ppp_names, par_names, extras)

  ## usage:  [y,u,t] = ${sys}_nppp (last, ppp_names, par_names, extras)
  ##
  ## last      last time in run
  ## ppp_names Column vector of names of ppp params
  ## par_names Column vector of names of estimated params
  ## extras    Structure containing additional info

  ##Sanity check
  if nargin<2
    printf("Usage: [y,u,t] = ${sys}_nppp(N, ppp_names[, par_names, extras])\n");
    return
  endif

    

  if nargin<4
    ## Set up optional parameters
    extras.criterion = 1e-3;
    extras.emulate_timing = 0;
    extras.max_iterations = 15;
    extras.simulate = 1;
    extras.v =  1e-6;










|

>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







|

|












<
<







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
#! /bin/sh

## nppp_rep.sh
## DIY representation "nppp" for mtt
# Copyright (C) 2002 by Peter J. Gawthrop

sys=$1
rep=nppp
lang=$2
mtt_parameters=$3
rep_parameters=$4

## Some names
target=${sys}_${rep}.${lang}
def_file=${sys}_def.r
dat2_file=${sys}_nppp.dat2
dat2s_file=${sys}_nppps.dat2
nppp_numpar_file=${sys}_nppp_numpar.m

## Get system information
if [ -f "${def_file}" ]; then
 echo Using ${def_file}
else
  mtt -q ${sys} def r
fi

ny=`mtt_getsize $1 y`
nu=`mtt_getsize $1 u`

## Help documentation
help_short() {
cat<<EOF
Nonlinear predictive pole placement
EOF
}

help_long() {
cat<<EOF
Details go here
EOF
}


## Make the _nppp.m file
make_nppp() {
filename=${sys}_${rep}.m
echo Creating ${filename}

cat > ${filename} <<EOF    
function [y,u,t] = ${sys}_nppp (last, ppp_names, par_names, A_u, A_w, w, Q, extras)

  ## usage:  [y,u,t] = ${sys}_nppp (last, ppp_names, par_names, A_u, A_w, w, Q, extras)
  ##
  ## last      last time in run
  ## ppp_names Column vector of names of ppp params
  ## par_names Column vector of names of estimated params
  ## extras    Structure containing additional info

  ##Sanity check
  if nargin<2
    printf("Usage: [y,u,t] = ${sys}_nppp(N, ppp_names[, par_names, extras])\n");
    return
  endif



  if nargin<4
    ## Set up optional parameters
    extras.criterion = 1e-3;
    extras.emulate_timing = 0;
    extras.max_iterations = 15;
    extras.simulate = 1;
    extras.v =  1e-6;
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
    printf("Open-loop interval %3.2f \n", simpar.last);
    printf(" -- using info in ${sys}_simpar.txt\n");
    printf("PPP optimisation from %3.2f to %3.2f\n", simpars.first, simpars.last);
    printf(" -- using info in s${sys}_simpar.txt\n");
  endif
  
  t_horizon = [simpars.first+simpars.dt:simpars.dt:simpars.last]';
  w = zeros(n_y,1); w(1) = 1
  w_s = ones(size(t_horizon))*w';

  ## Setup the indices of the adjustable stuff
  if nargin<2
    i_ppp = []
  else
    i_ppp = ppp_indices (ppp_names,sympar,sympars); # Parameters
  endif

  n_ppp = length(i_ppp(:,1));

  if nargin<3
    i_par = []
  else
    i_par = ppp_indices (par_names,sympar,sympars); # Parameters
  endif
  
  ## Specify basis functions
  A_w = zeros(1,1);
  A_u = ppp_aug(A_w,laguerre_matrix(n_ppp-1,2.0));

  ## Weights
    Q = [1;0]

  if extras.visual		# Do some simulations
    ## 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;







<

















<
<
<
<
<
<







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
    printf("Open-loop interval %3.2f \n", simpar.last);
    printf(" -- using info in ${sys}_simpar.txt\n");
    printf("PPP optimisation from %3.2f to %3.2f\n", simpars.first, simpars.last);
    printf(" -- using info in s${sys}_simpar.txt\n");
  endif
  
  t_horizon = [simpars.first+simpars.dt:simpars.dt:simpars.last]';

  w_s = ones(size(t_horizon))*w';

  ## Setup the indices of the adjustable stuff
  if nargin<2
    i_ppp = []
  else
    i_ppp = ppp_indices (ppp_names,sympar,sympars); # Parameters
  endif

  n_ppp = length(i_ppp(:,1));

  if nargin<3
    i_par = []
  else
    i_par = ppp_indices (par_names,sympar,sympars); # Parameters
  endif
  







  if extras.visual		# Do some simulations
    ## 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;
159
160
161
162
163
164
165















































166
167
168
169
170
171
172
    system("gv ${sys}_y.eps&");
    system("gv ${sys}_u.eps&");
  endif
endfunction

EOF
}
















































make_model() {
    
echo "Making sensitivity simulation for system ${sys} (lang ${lang})"

if [ "${lang}" = "oct" ]; then
    oct='-oct'







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
228
229
230
231
232
233
234
235
236
237
238
239
    system("gv ${sys}_y.eps&");
    system("gv ${sys}_u.eps&");
  endif
endfunction

EOF
}

make_nppp_numpar() {
echo Creating ${nppp_numpar_file}
cat > ${sys}_nppp_numpar.m <<EOF
function [last, ppp_names, par_names, A_u, A_w, w, Q, extras] = ${sys}_nppp_numpar 

## usage:  [last, ppp_names, par_names, A_u, A_w, w, Q, extras] = ${sys}_nppp_numpar ()
##
## 

  ## Last time of run
  last = 10;

  ## Specify basis functions
  A_w = zeros(1,1);
  n_ppp = ${nu};
  A_u = ppp_aug(A_w,laguerre_matrix(n_ppp-1,2.0));

 
  ## Names of ppp parameters
  ppp_names = "";
  for i=1:n_ppp
    name = sprintf("ppp_%i", i);
    ppp_names = [ppp_names; name];
  endfor

  ## Estimated parameters
  par_names = [];

  ## Weights
  Q = ones(${ny},1);

  ## Setpoint
  w = zeros(${ny},1); w(1) = 1;

  ## Set up optional parameters
  extras.criterion = 1e-3;
  extras.emulate_timing = 0;
  extras.max_iterations = 15;
  extras.simulate = 1;
  extras.v =  1e-6;
  extras.verbose = 0;
  extras.visual = 0;

endfunction
EOF
}

make_model() {
    
echo "Making sensitivity simulation for system ${sys} (lang ${lang})"

if [ "${lang}" = "oct" ]; then
    oct='-oct'
193
194
195
196
197
198
199

200


201


















202



203
























204









## Additional system reps for PPP
mtt -q ${mtt_parameters} -stdin  ${sys} sm m
mtt -q ${mtt_parameters} -stdin  ${sys} def m
mtt -q ${mtt_parameters} -stdin  -s s${sys} def m

}


## Make the code


#


















#make_model;



make_nppp;









































>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
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
## Additional system reps for PPP
mtt -q ${mtt_parameters} -stdin  ${sys} sm m
mtt -q ${mtt_parameters} -stdin  ${sys} def m
mtt -q ${mtt_parameters} -stdin  -s s${sys} def m

}

make_dat2() {

## Inform user
echo Creating ${dat2_file}

## Use octave to generate the data
octave -q <<EOF
  [last, ppp_names, par_names, A_u, A_w, w, Q, extras] = ${sys}_nppp_numpar;
  [y,u,t] = ${sys}_nppp(last, ppp_names, par_names, A_u, A_w, w, Q, extras);
  data = [t,y,u];
  save -ascii ${dat2_file} data
EOF
}

case ${lang} in
    help_short)
        help_short
        ;;
    help_long)
        help_long
        ;;
    numpar.m)
        ## Make the numpar stuff
        make_nppp_numpar;
	;;
    m)
        ## Make the code
        make_nppp;
	;;
    dat2)
	## The dat2 language (output data)
	if [ -f "${dat2_file}" ]; then
	  if [ "${dat2_file}" -ot "${nppp_numpar_file}" ]; then
	    make_dat2; 
	  else 
	    echo Using ${dat2_file}
	  fi
	else
	  make_dat2;    
        fi
	;;
    gdat)
        cp ${dat2_file} ${dat2s_file} 
	dat22dat ${sys} ${rep} 
        dat2gdat ${sys} ${rep}
	;;
    fig)
	gdat2fig ${sys}_${rep}
	;;
    ps)
	fig2dev -Leps ${sys}_${rep}.fig > ${sys}_${rep}.ps
	;;

    view)
	
	;;
    *)
	echo Language ${lang} not supported by nppp representation
        exit 3
esac



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