Overview
Comment:Updated for new PPP
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: a6be83f05796746b98ea6d145ef98b2add3934450793fde9881c5ed59a98eff2
User & Date: gawthrop@users.sourceforge.net on 2005-09-07 18:30:36
Other Links: branch diff | manifest | tags
Context
2005-09-07
18:31:40
Updated check-in: df2c33dea2 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
18:30:36
Updated for new PPP check-in: a6be83f057 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
18:29:33
Use ss not sys2ss check-in: 79bceb1078 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/lib/control/PPP/ppp_are.m from [61fa06621b] to [fabd8baa32].

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  if n_q==n_y			# Output weight
    Q_x =  C'*Q*C;		# Weighting on x
  elseif n_q==n_x		# State weight
    Q_x = Q;
  else
    error(sprintf("Q (%ix%i) must be %ix%i or %ix%i",n_q,n_q,n_y,n_y,n_x,n_x));
  endif
  Q_x
  [k, P, poles] = lqr (A, B, Q_x, R) # Algebraic Riccati solution

  ## Basis functions
  if strcmp(A_type,"companion")
    A_u = compan(poly(poles));
  elseif strcmp(A_type,"feedback")
    A_u = A-B*k;
  else







|
|







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  if n_q==n_y			# Output weight
    Q_x =  C'*Q*C;		# Weighting on x
  elseif n_q==n_x		# State weight
    Q_x = Q;
  else
    error(sprintf("Q (%ix%i) must be %ix%i or %ix%i",n_q,n_q,n_y,n_y,n_x,n_x));
  endif

  [k, P, poles] = lqr (A, B, Q_x, R); # Algebraic Riccati solution

  ## Basis functions
  if strcmp(A_type,"companion")
    A_u = compan(poly(poles));
  elseif strcmp(A_type,"feedback")
    A_u = A-B*k;
  else

Modified mttroot/mtt/lib/control/PPP/ppp_ustar2h.m from [07b58f747a] to [ec1d4f0005].

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
function ppp_ustar2h (Ustar,name)

  ## usage:  ppp_Ustar2h (Ustar[,name])
  ##
  ## 

  if nargin<2




    name = "Ustar";
  endif

  [N,N_U] = size(Ustar);

  ## Open the file 
  filename = sprintf("%s.h", name);
  fid = fopen(filename,"w");

  ## Header
  header = sprintf("/*\n File %s generated by ppp_ustar2h on %s */\n", \
		   filename, ctime(time));

  def = sprintf("#define N_U %i\n#define N_T %i\n", N_U, N);



  fprintf(fid, "%s%sdouble %s[N_T][N_U] = {\n",header,def,name);
  for i=1:N
    fprintf(fid, "{");
    for j=1:N_U
      if j<N_U
	comma = ",";
|






>
>
>
>













|
>
>







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
function ppp_ustar2h (Ustar,DT,name)

  ## usage:  ppp_Ustar2h (Ustar[,name])
  ##
  ## 

  if nargin<2
    DT = 1;
  endif
  
  if nargin<3
    name = "Ustar";
  endif

  [N,N_U] = size(Ustar);

  ## Open the file 
  filename = sprintf("%s.h", name);
  fid = fopen(filename,"w");

  ## Header
  header = sprintf("/*\n File %s generated by ppp_ustar2h on %s */\n", \
		   filename, ctime(time));

  def = sprintf("#define N_U %i\n#define N_T %i\n#define DT %g\n", \
		 N_U, N, DT);
  def = sprintf("%sdouble U[N_U];\n",def);

  fprintf(fid, "%s%sdouble %s[N_T][N_U] = {\n",header,def,name);
  for i=1:N
    fprintf(fid, "{");
    for j=1:N_U
      if j<N_U
	comma = ",";

Modified mttroot/mtt/lib/control/PPP/ppp_ystar.m from [17c1b7c256] to [0c38479f43].

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
function [ys,us,xs,xu,AA] = ppp_ystar (A,B,C,D,x_0,A_u,U,tau)

  ## usage:  [ys,us,xs,xu,AA] = ppp_ystar (A,B,C,D,x_0,A_u,U,tau)
  ##
  ## Computes open-loop moving horizon variables at time tau
  ## Inputs:
  ## A,B,C,D     System matrices
  ## x_0         Initial state
  ## A_u         composite system matrix for U* generation 
  ##             one square matrix (A_ui) row for each system input
  ##             each A_ui generates U*' for ith system input.
  ## OR
  ## A_u         square system matrix for U* generation 
  ##             same square matrix for each system input
  ## U           Column vector of optimisation coefficients  
  ## tau         Row vector of times at which outputs are computed

  ## Outputs:
  ## ys          y*, one column for each time tau 
  ## us          u*, one column for each time tau 
  ## xs          x*, one column for each time tau 
  ## xu          x_u, one column for each time tau 
  ## AA          The composite system matrix
  

  ## Copyright (C) 1999 by Peter J. Gawthrop
  ## 	$Id$	

  if (size(A)>0)
    [n_x,n_u,n_y] = abcddim(A,B,C,D); # System dimensions
  else
    n_x = 0;
    n_y = 0;
    n_u = 0;
  endif
  
  no_system = n_x==0;

  [n,m] = size(A_u);		# Size of composite A_u matrix
  square = (n==m);		# Is A_u square?
  n_U = m;			# functions per input

  
  [n,m] = size(U);
  if (m != 1)
    error("U must be a column vector");
  endif
  
  if n_u>0
    if n_u!=length(U)/n_U
|

|













>







>
|
















<







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
function [ys,us,xs,xu,AA] = ppp_ystar (A,B,C,D,x_0,A_u,U,tau,Us0)

  ## usage:  [ys,us,xs,xu,AA] = ppp_ystar (A,B,C,D,x_0,A_u,U,tau[,Us0])
  ##
  ## Computes open-loop moving horizon variables at time tau
  ## Inputs:
  ## A,B,C,D     System matrices
  ## x_0         Initial state
  ## A_u         composite system matrix for U* generation 
  ##             one square matrix (A_ui) row for each system input
  ##             each A_ui generates U*' for ith system input.
  ## OR
  ## A_u         square system matrix for U* generation 
  ##             same square matrix for each system input
  ## U           Column vector of optimisation coefficients  
  ## tau         Row vector of times at which outputs are computed
  ## Us0         Initial value of U* (default ones(NU,1))
  ## Outputs:
  ## ys          y*, one column for each time tau 
  ## us          u*, one column for each time tau 
  ## xs          x*, one column for each time tau 
  ## xu          x_u, one column for each time tau 
  ## AA          The composite system matrix
  

  ## Copyright (C) 1999,2005 by Peter J. Gawthrop
  ## 	$Id$	

  if (size(A)>0)
    [n_x,n_u,n_y] = abcddim(A,B,C,D); # System dimensions
  else
    n_x = 0;
    n_y = 0;
    n_u = 0;
  endif
  
  no_system = n_x==0;

  [n,m] = size(A_u);		# Size of composite A_u matrix
  square = (n==m);		# Is A_u square?
  n_U = m;			# functions per input


  [n,m] = size(U);
  if (m != 1)
    error("U must be a column vector");
  endif
  
  if n_u>0
    if n_u!=length(U)/n_U
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
  endif
  

  [n,m]=size(tau);
  if (n != 1 )
    error("tau must be a row vector of times");
  endif










  
  if square			# Then same A_u for each input
    ## Reorganise vector U into matrix Utilde  
    Utilde = [];
    for i=1:n_u
      j = (i-1)*n_U;
      range = j+1:j+n_U;
      Utilde = [Utilde; U(range,1)'];
    endfor

    ## Composite A matrix
    if no_system
      AA = A_u;
    else
      Z = zeros(n_U,n_x);
      AA = [A   B*Utilde
	    Z   A_u];
    endif
    
    xx_0 = [x_0;ones(n_U,1)];	# Composite initial condition
  else				# Different A_u on each input
    ## Reorganise vector U into matrix Utilde  
    Utilde = [];
    for i=1:n_u
      j = (i-1)*n_U;
      k = (n_u-i)*n_U;
      range = j+1:j+n_U;







>
>
>
>
>
>
>
>
>
>



















|







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
  endif
  

  [n,m]=size(tau);
  if (n != 1 )
    error("tau must be a row vector of times");
  endif

  if nargin<9
    Us0 = ones(1,n_U);
  endif
  
  [n_Us0,m_Us0] = size(Us0);
  if (n_Us0>1)||(n_Us0>m_Us0)
    error(sprintf("Us0 must be a row vector, not %ix%i ",n_Us0,m_Us0));
  endif
	  
  
  if square			# Then same A_u for each input
    ## Reorganise vector U into matrix Utilde  
    Utilde = [];
    for i=1:n_u
      j = (i-1)*n_U;
      range = j+1:j+n_U;
      Utilde = [Utilde; U(range,1)'];
    endfor

    ## Composite A matrix
    if no_system
      AA = A_u;
    else
      Z = zeros(n_U,n_x);
      AA = [A   B*Utilde
	    Z   A_u];
    endif
    
    xx_0 = [x_0;Us0'];		# Composite initial condition
  else				# Different A_u on each input
    ## Reorganise vector U into matrix Utilde  
    Utilde = [];
    for i=1:n_u
      j = (i-1)*n_U;
      k = (n_u-i)*n_U;
      range = j+1:j+n_U;


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