File mttroot/mtt/bin/trans/smc2ssk_r artifact 06844ee033 part of check-in a0d28fdb76


#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: smc2ssk_r
# controller-form state matrices to controller gain k
# P.J.Gawthrop  Jan 1998
# Copyright (c) P.J.Gawthrop 1998

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.3  1998/02/09 14:16:52  peterg
## Writes end statement to the o/p file
##
## Revision 1.2  1998/01/23 09:30:36  peterg
## Fixed a sign error - the coeficients of a(s) appear with - signs in
## the A_c matrix!
##
## Revision 1.1  1998/01/22 13:16:16  peterg
## Initial revision
##
###############################################################

Nu=`mtt_getsize $1 u`
Ny=`mtt_getsize $1 y`

if [ "$Nu" = "1" ]; then
  if [ "$Ny" = "1" ]; then
    blurb=' for this siso system'    
  else
    blurb=" using first output of $Ny"
  fi
else
  if [ "$Ny" = "1" ]; then
    blurb=" using first input of $Nu"
  else
    blurb=" using first input of $Nu and using first output of $Ny"
  fi
fi

# Inform user
echo Creating $1_ssk.r $blurb

# Remove the old log file
rm -f smc2ssk_r.log

# Use reduce to accomplish the transformation
reduce >smc2ssk_r.log << EOF

in "$1_def.r";
in "$1_smc.r";

%Read the formatting function
in "$MTTPATH/trans/reduce_matrix.r";


OFF Echo;
OFF Nat;


%%%%  Controller design %%%%%

% gain in controller form:
matrix MTTk_c(1,MTTNx);

matrix alpha_c(9,1);
alpha_c(1,1) := alpha_c1;
alpha_c(2,1) := alpha_c2;
alpha_c(3,1) := alpha_c3;
alpha_c(4,1) := alpha_c4;
alpha_c(5,1) := alpha_c5;
alpha_c(6,1) := alpha_c6;
alpha_c(7,1) := alpha_c7;
alpha_c(8,1) := alpha_c8;
alpha_c(9,1) := alpha_c9;


for i := 1:MTTNx do
 MTTk_c(1,i) := alpha_c(i,1) + MTTA_c(1,i);

% Gain in physical form
MTTk := MTTk_c*MTTT_c;


%Create the output file
OUT "$1_ssk.r";

%Write out the matrices.

write "%  - Gain matrix - controller form";
MTT_Matrix := MTTK_c$ 
MTT_Matrix_name := "MTTK_c"$
MTT_Matrix_n := 1$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "%  - Gain matrix - physical form";
MTT_Matrix := MTTK$ 
MTT_Matrix_name := "MTTK"$
MTT_Matrix_n := 1$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "END;";

SHUT "$1_ssk.r";
quit;

EOF

# Now invoke the standard error handling.
mtt_error_r smc2ssk_r.log


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