Overview
Comment:Preliminary version of new style DIY rep for nppp
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: e9534741f1b2105c5091f6c958747986e234e9af4025151a72e974e655c8158f
User & Date: gawthrop@users.sourceforge.net on 2002-05-08 11:37:30
Other Links: branch diff | manifest | tags
Context
2002-05-08
11:39:36
Added MTT_REP to PATH check-in: f20e8408f6 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
11:37:30
Preliminary version of new style DIY rep for nppp check-in: e9534741f1 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
10:14:21
Idetification now OK (Moved data range in ppp_optimise by one sample interval) check-in: d489277969 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Added mttroot/mtt/lib/rep/nppp_rep.sh version [149fe751d7].















































































































































































































































































































































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

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

sys=$1
rep=nppp
lang=$2

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 (N, 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-5;
    extras.emulate_timing = 0;
    extras.max_iterations = 10;
    extras.simulate = 1;
    extras.v =  1e-6;
    extras.verbose = 0;
    extras.visual = 0;
  endif
  
  ## System info
  [n_x,n_y,n_u,n_z,n_yz] = ${sys}_def;
  sympar  = ${sys}_sympar;
  simpar  = ${sys}_simpar;
  sympars  = s${sys}_sympar;
  simpars  = s${sys}_simpar;
  t_ol = simpar.last;
    
  ## Number of intervals needed
  N = ceil(last/t_ol);

  ## Setpoints
  if extras.verbose
    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,5.0));


  ## Do it
  [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,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,:);

  if extras.visual
    ## Plots
    gset grid; xlabel "Time (sec)"; title "${sys}"
    ty = [t y] ; 
    tu =  [t u]; 
  
    ty_open = [T_open y_open];
    tu_open = [T_open u_open];
  
    gplot  tu \
        title "u", tu_open with impulses title "Sample times"
    figfig("${sys}_u","eps");
  
    gplot  ty \
        title "y", ty_open with impulses title "Sample times"
    figfig("${sys}_y","eps");
  
    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'
fi

## System
mtt -q -stdin ${sys} sympar m
mtt -q -stdin ${sys} simpar m
mtt -q -stdin ${oct} ${sys} state ${lang}
mtt -q -stdin ${oct} ${sys} numpar ${lang}
mtt -q -stdin ${oct} ${sys} input ${lang}
mtt -q -stdin ${oct} ${sys} ode2odes ${lang}
mtt -q -stdin ${sys} sim m

## Sensitivity system
mtt -q -stdin -s s${sys} sympar m
mtt -q -stdin -s s${sys} simpar m
mtt -q -stdin ${oct} -s s${sys} state ${lang}
mtt -q -stdin ${oct} -s s${sys} numpar ${lang}
mtt -q -stdin ${oct} -s s${sys} input ${lang}
mtt -q -stdin ${oct} -s s${sys} ode2odes ${lang}
mtt -q -stdin -s s${sys} ssim m

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

}

## Make the code
make_model;
make_nppp;


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