BeginPackage["Compensators`"]

Off[General::"spell1"]
Off [General::"spell"]
InitializationNB = SelectedNotebook[];

\(\(\( (*GENERAL\ MATRIX\ MANIPULATION\ FUNCTIONS*) \)\(
\)\(
\)\(MatElLCM[
        x_] := 
\((
Apply[PolynomialLCM, 
          Flatten[x]]
)\)\)\)\)

\(\(\(MatElGCD[
        x_] := 
\((
Apply[PolynomialGCD, 
          Flatten[x]]
)\)\)\(
\)
    \)\)

Rank[x_] := Last[Dimensions[x]] - Length[NullSpace[x]]

AddZeroBlocks[x_, y_, z_] := 
      Module[{d, X, TX, TPX, 
          AX}, 
(
d = 
            Dimensions[x]; 
X = x; 
Do[
            X[[i]] = PadRight[x[[i]], d[[2]] + z], {i, 1, 
              d[[1]]}]; 
TX = 
            Transpose[X]; 
TPX = TX; 
Do[
            TPX[[i]] = PadRight[TX[[i]], d[[1]] + y], {i, 1, 
              d[[2]] + z}]; 
AX = 
            Transpose[TPX]
)]

SmithForm[x_] := 
      Module[{r, dim, m, mn, Sm0, 
          Sm}, 
(
r = 
            Rank[x]; 
dim = Dimensions[x]; m = Range[r]; 
          Do[m[[l]] = MatElGCD[Minors[x, l]], {l, 1, 
              r}]; 
mn = m; 
          Do[mn[[b]] = mn[[b]]/m[[b - 1]], {b, 2, 
              r}]; 
Sm0 = 
            DiagonalMatrix[mn]; 
Sm = 
            AddZeroBlocks[Sm0, dim[[1]] - r, 
              dim[[2]] - r]; 
Factor[
            Sm]
)]

McMillanForm[x_] := 
      Module[{DenMat, denGCD, NS, SN, MX1, MX2, 
          MX}, 
(
DenMat = 
            Denominator[x]; 
denGCD = 
            MatElGCD[DenMat]; 
NS = 
            denGCD x; 
SN = 
            SmithForm[NS]; 
MX1 = 
            SN/denGCD; 
MX2 = 
            Cancel[MX1]; 
MX = 
            Factor[MX2]
)]

DeleteLastBlocks[x_, p_, m_] := 
      Module[{DimX, R1, R2, X1, 
          X2}, 
(
DimX = 
            Dimensions[x]; 
R1 = 
            Partition[Range[DimX[[2]] + 1 - m, DimX[[2]]], 
              1]; 
R2 = 
            Partition[Range[DimX[[1]] + 1 - p, DimX[[1]]], 
              1]; 
X1 = 
            Delete[Transpose[x], R1]; 
X2 = 
            Delete[Transpose[X1], R2]
)]

VerticalBlockMatrix[x_List] := 
      Module[{nb, AllMatricesQ, 
          Columns}, 
(
nb = 
            Length[x]; 
If[
            AllMatricesQ = 
              Apply[And, Map[MatrixQ, x]], (If[
                Apply[Equal, Map[Dimensions, x][[All, 
                      2]]], (Columns = Dimensions[
                        x[[1]]][[2]]; 
                  Partition[Flatten[x], Columns]), 
                Message[VerticalBlockMatrix::dims, x]]), 
            Message[VerticalBlockMatrix::arg, 
              x]]
)]
VerticalBlockMatrix::dims := "Elements of `1` consist of different \
number of columns"
VerticalBlockMatrix::arg := "`1` is not a list of matrices"

\(\(\(HorizontalBlockMatrix[x_List] := 
      Module[{AllMatricesQ}, 
\((
If[
            AllMatricesQ = 
              Apply[And, Map[MatrixQ, x]], \((If[
                Apply[Equal, \(Map[Dimensions, x]\)[\([All, 1]\)]], 
                Map[Flatten, Transpose[x]], 
                Message[HorizontalBlockMatrix::dims, x]])\), 
            Message[HorizontalBlockMatrix::arg, x]]
)\)]

    HorizontalBlockMatrix::dims := "Elements of `1` consist of different number of rows"

    HorizontalBlockMatrix::arg := "`1` is not a list of matrices"\)\(\ \)\)\)

DegDifference[x_, var_] :=  
      Exponent[Numerator[x], var] - Exponent[Denominator[x], var]

MinFiniteDegreeDiff[x_List, var1_] := 
      Module[{MDD}, 
(
MDD = ∞; 
Do[
            If[DegDifference[Flatten[x][[k]], 
                  var1] ≠ -∞, 
              MDD = Min[MDD, 
                  DegDifference[Flatten[x][[k]], var1]]], {k, 1, 
              Length[Flatten[
                  x]]}]; 
MDD
)]

ColumnPermutation[x_, y_, z_] := 
      Module[{IPerm}, 
(
IPerm = 
            IdentityMatrix[Dimensions[
                  x][[-1]]]; 
IPerm[[y, y]] = 
            0; 
IPerm[[z, z]] = 
            0; 
IPerm[[y, z]] = 
            1; 
IPerm[[z, y]] = 
            1; 
{x . IPerm, 
            IPerm}
)]

PolynomialReduceQuotients[n_List, d_, var_] := 
      Module[{qlist0}, 
(
qlist0 = 
            n; 
Do[
            qlist0[[i]] = PolynomialQuotient[n[[i]], d, var], {i, 1, 
              Length[n]}]; qlist0
)]

PRQuotient[pr1_, pr2_, var_] := 
      Module[{n1, d1, n2, d2}, (n1 = Numerator[pr1]; 
          d1 = Denominator[pr1]; 
n2 = Numerator[pr2]; 
          d2 = Denominator[pr2]; 
PolynomialQuotient[n1*d2, 
            n2*d1, var])]

PRRemainder[pr1_, pr2_, var_] := 
      Module[{n1, d1, n2, d2}, (n1 = Numerator[pr1]; 
          d1 = Denominator[pr1]; 
n2 = Numerator[pr2]; 
          d2 = Denominator[pr2]; 
FullSimplify[
            PolynomialRemainder[n1*d2, n2*d1, 
                var]/(d1*d2)])]

PRReduceQuotients[n_List, d_, var_] := 
      Map[PRQuotient[#, d, var] &, n]

RowDegreeReduction[x_, r1_, c1_, v_] := 
      Module[{rn, TM, med, cpos, PM, TX, RP, RPQ, IDX, 
          ITX}, 
(
rn = 
            x[[r1, 
                Range[c1, Dimensions[
                      x][[-1]]]]]; 
TM = 
            IdentityMatrix[Dimensions[
                  x][[-1]]]; 
med = 
            MinFiniteDegreeDiff[rn, v]; 
cpos = 
            Flatten[Position[DegDifference[rn, v], med][[1]]] + c1 - 
              1; 
PM = 
            ColumnPermutation[x, c1, cpos]; 
TX = 
            PM[[1]]; 
TM = 
            TM . PM[[2]];  
RP = 
            TX[[r1, 
                Range[c1 + 
                    1, Dimensions[
                      TX][[-1]]]]]; 
RPQ = 
            PRReduceQuotients[RP, TX[[r1, c1]], 
              v]; 
IDX = 
            IdentityMatrix[Dimensions[
                  TX][[-1]]]; 
ITX = 
            IDX; 
ITX[[r1, 
                Range[c1 + 
                    1, Dimensions[
                      TX][[-1]]]]] = -RPQ; 
TM = TM . ITX; 
Factor[
            Simplify[{x . TM, TM}]]
)]

ZeroVector[n_] := 0*Range[1, n]

\(PolynomialMatrixColumnRealCoefficientSimplify[m_, vr1_] := 
      Module[{cc, 
          IT0}, 
\ \ \ \ \((
\ \ \ \ \ \ cc = 
            CoefficientList[Transpose[m], vr1] /. {} -> 
                0; 
\ \ \ \ \ \ IT0 = 
            IdentityMatrix[\(Dimensions[m]\)[\([\(-1\)]\)]]; 
\ \ \ \ \ \ Do[
            If[MatElGCD[cc[\([g]\)]] ≠ 0, 
              IT0[\([g, g]\)] = 
                1/MatElGCD[cc[\([g]\)]], 
\ \ \ \ \ \ \ \ \ \ IT0[\([g, 
                    g]\)] = 1], {g, 
              1, \(Dimensions[
                  m]\)[\([\(-1\)]\)]}]; 
\ \ \ \ \ \ Simplify[{m . IT0, 
              IT0}]
\ \ \ \ \ \ )\)]\)

RationalMatrixColumnRealCoefficientSimplify[m_List, var_] := 
      Module[{NumeratorReductionMatrix, DenominatorReductionMatrix, IT0, 
          RightTransformationMatrix, 
          cc}, (NumeratorReductionMatrix = PolynomialMatrixColumnRealCoefficientSimplify[Numerator[m], 
                var][[2]]; 
DenominatorReductionMatrix = (cc = 
                Map[Part[#, -1] &, 
                  CoefficientList[Transpose[Denominator[m]], 
                      var] /. (0 -> 
                        1), {2}]; 
IT0 = 
                IdentityMatrix[Dimensions[
                      m][[-1]]]; 
Do[
                IT0[[g, g]] = 1/MatElLCM[cc[[g]]], {g, 
                  1, Dimensions[m][[-1]]}]; 
              IT0 /. 0 -> 
                  1); 
RightTransformationMatrix = 
            DiagonalMatrix[
              Table[NumeratorReductionMatrix[[i, i]]/
                  DenominatorReductionMatrix[[i, i]], {i, 
                  Length[IT0]}]]; 
Factor[
            Simplify[{m . RightTransformationMatrix, 
                RightTransformationMatrix}]])]

LeftStructureMatrix[RationalMatrix_List, var_] := 
      Module[{StructureMatrixLeft, ColumnTransformationMatrix, 
          ElementaryTransformationMatrix}, 
(
StructureMatrixLeft = 
            RationalMatrix; 
ColumnTransformationMatrix = 
            IdentityMatrix[Dimensions[
                  RationalMatrix][[2]]]; 
Do[
            While[StructureMatrixLeft[[i, 
                      Range[i + 
                          1, Dimensions[
                            StructureMatrixLeft][[2]]]]]/(StructureMatrixLeft[[i, 
                          Range[i + 
                              1, Dimensions[
                                StructureMatrixLeft][[2]]]]] /.  
                      0 -> 1) ≠ 
                ZeroVector[Dimensions[StructureMatrixLeft][[2]] - 
                    i], {StructureMatrixLeft, 
                  ElementaryTransformationMatrix} = 
                RowDegreeReduction[StructureMatrixLeft, i, i, var]; 
              ColumnTransformationMatrix = 
                ColumnTransformationMatrix . 
                  ElementaryTransformationMatrix], {i, 1, 
              Length[RationalMatrix]}]; 
{StructureMatrixLeft, ElementaryTransformationMatrix} = 
            RationalMatrixColumnRealCoefficientSimplify[StructureMatrixLeft, 
              var]; ColumnTransformationMatrix = 
            ColumnTransformationMatrix . 
              ElementaryTransformationMatrix; 
Factor[
            Simplify[{StructureMatrixLeft, 
                ColumnTransformationMatrix}]]
)]

RightStructureMatrix[X_, v0_] := 
      Module[{TSX, TXLSM, RSM, 
          LTRMAT}, 
(
TSX = 
            Transpose[X]; 
TXLSM = 
            LeftStructureMatrix[TSX, v0]; 
RSM = 
            Transpose[TXLSM[[1]]]; 
LTRMAT = 
            Transpose[TXLSM[[2]]]; 
{RSM, 
            LTRMAT}
)]

PMLeftGCD[x_List, var_] := 
      Module[{T0, T1, T2, 
          LeftGCD}, 
(
T0 = 
            HorizontalBlockMatrix[
              x]; 
T1 = LeftStructureMatrix[T0, 
                var][[1]]; 
T2 = 
            Transpose[T1]; 
LeftGCD = 
            Transpose[
              T2[[Range[
                    1, Dimensions[
                        T1][[1]]]]]]
)]

PMRightGCD[x_List, var_] := 
      Module[{T0, T1, 
          RightGCD}, 
(
T0 = 
            VerticalBlockMatrix[
              x]; 
T1 = RightStructureMatrix[T0, 
                var][[1]]; 
RightGCD = 
            T1[[Range[
                  1, Dimensions[
                      T1][[-1]]]]]
)]

SimplifyRightMFDCoefficients[nom_List, den_List, var_] := 
      Module[{MFD, SimpleMFD, MFDTransformationMatrix, SimpleNR, SimpleDR, M, 
          TRANSMAT, DenominatorElementsHiCoef, NegC, 
          PosC}, 
(
MFD = 
            Join[nom, den]; 
{SimpleMFD, 
              MFDTransformationMatrix} = 
            RationalMatrixColumnRealCoefficientSimplify[MFD, 
              var]; 
SimpleNR = 
            nom; 
SimpleDR = den; 
Do[
            If[i ≤ Length[nom], 
              SimpleNR = ReplacePart[SimpleNR, SimpleMFD[[i]], i], 
              SimpleDR = 
                ReplacePart[SimpleDR, SimpleMFD[[i]], 
                  i - Length[nom]]], {i, 
              Length[MFD]}]; 
M = 
            HighestRowDegreeCoefficientMatrix[SimpleDR, 
              var]; 
If [Det[M] ≠ 0, 
            TRANSMAT = LinearSolve[M, IdentityMatrix[Length[M]]]; 
            SimpleDR = Factor[Simplify[SimpleDR . TRANSMAT]]; 
            SimpleNR = 
              Factor[Simplify[
                  SimpleNR . TRANSMAT]]]; 
{SimpleDR, 
              TRANSMAT} = 
            LeftStructureMatrix[SimpleDR, var]; 
SimpleNR = 
            Factor[Simplify[SimpleNR . TRANSMAT]]; 
          DenominatorElementsHiCoef = 
            Partition[
              MapThread[
                Coefficient, {Flatten[var*SimpleDR], 
                  var^Flatten[
                      Exponent[SimpleDR*var, var] /. -Infinity -> 
                          1]}], Dimensions[SimpleDR][[2]]]; 
          NegC = Map[Count[#, x_ /; x < 0] &, 
              Transpose[DenominatorElementsHiCoef]]; 
          PosC = Map[Count[#, x_ /; x > 0] &, 
              Transpose[DenominatorElementsHiCoef]]; 
          TRANSMAT = 
            DiagonalMatrix[
              Map[If[# < 0, -1, 1] &, 
                PosC - NegC]]; 
{Factor[
              Simplify[SimpleNR . TRANSMAT]], 
            Factor[Simplify[
                SimpleDR . TRANSMAT]]}
)]

SimplifyLeftMFDCoefficients[den_List, nom_List, var_] := 
      Module[{MFD, SimpleMFD, MFDTransformationMatrix, SimpleNL, SimpleDL, M, 
          TrTRANSMAT, TRANSMAT, DenominatorElementsHiCoef, NegC, 
          PosC}, 
(
MFD = 
            Join[Transpose[den], 
              Transpose[nom]]; 
{SimpleMFD, 
              MFDTransformationMatrix} = 
            RationalMatrixColumnRealCoefficientSimplify[MFD, 
              var]; 
SimpleDL = 
            Transpose[den]; 
SimpleNL = 
            Transpose[nom]; 
Do[
            If[i ≤ Length[SimpleDL], 
              SimpleDL = ReplacePart[SimpleDL, SimpleMFD[[i]], i], 
              SimpleNL = 
                ReplacePart[SimpleNL, SimpleMFD[[i]], 
                  i - Length[SimpleDL]]], {i, 
              Length[MFD]}]; 
{SimpleDL, 
              SimpleNL} = {Transpose[SimpleDL], 
              Transpose[SimpleNL]}; 
M = 
            HighestColumnDegreeCoefficientMatrix[
              SimpleDL]; 
If [Det[M] ≠ 0, 
            TrTRANSMAT = 
              LinearSolve[Transpose[M], IdentityMatrix[Length[M]]], 
            TRANSMAT = Transpose[TrTRANSMAT]; 
            SimpleDL = Factor[Simplify[TRANSMAT . SimpleDL]]; 
            SimpleNL = 
              Factor[Simplify[
                  TRANSMAT . SimpleNL]]]; 
{SimpleDL, 
              TRANSMAT} = RightStructureMatrix[SimpleDL, var]; 
          SimpleNL = Factor[Simplify[TRANSMAT . SimpleNL]]; 
          DenominatorElementsHiCoef = 
            Partition[
              MapThread[
                Coefficient, {Flatten[var*SimpleDL], 
                  var^Flatten[
                      Exponent[SimpleDL*var, var] /. -Infinity -> 
                          1]}], Dimensions[SimpleDL][[2]]]; 
          NegC = Map[Count[#, x_ /; x < 0] &, DenominatorElementsHiCoef]; 
          PosC = Map[Count[#, x_ /; x > 0] &, DenominatorElementsHiCoef]; 
          TRANSMAT = 
            DiagonalMatrix[
              Map[If[# < 0, -1, 1] &, 
                PosC - NegC]]; 
{Factor[
              Simplify[TRANSMAT . SimpleDL]], 
            Factor[Simplify[
                TRANSMAT . SimpleNL]]}
)]

RightMFD[x_] := 
      Module[{dims, DX, TDX, V, 
          B0}, 
(
dims = 
            Dimensions[x]; 
DX = 
            Denominator[x]; 
TDX = 
            Transpose[DX]; 
V = 
            Range[1, dims[[-1]]]; 
Do[
            V[[i]] = MatElLCM[TDX[[i]]], {i, 1, 
              dims[[-1]]}]; 
B0 = 
            DiagonalMatrix[V]; 
Factor[
            Simplify[{x . B0, B0}]]
)]

RightCoprimeMFD[x_, var_] := 
      Module[{PM1, PM2, 
          rightgcd}, 
(
{PM1, PM2} = 
            RightMFD[x]; 
rightgcd = 
            PMRightGCD[{PM1 , PM2}, var]; 
If[
            NumberQ[Det[rightgcd] /. 
                ConstantsList -> Range[1, Length[ConstantsList]]], {PM1, 
              PM2}, PM1 = PM1 . Inverse[rightgcd]; 
            PM2 = PM2 . Inverse[rightgcd]]; 
{PM1, PM2} = 
            SimplifyRightMFDCoefficients[Factor[Simplify[PM1]], 
              Factor[Simplify[PM2]], var]
)]

LeftMFD[x_] := 
      Module[{dims, DX, 
          LeftDenMat}, 
(
dims = 
            Dimensions[x]; 
DX = 
            Denominator[x]; 
LeftDenMat = 
            Range[1, dims[[1]]]; 
Do[
            LeftDenMat[[i]] = MatElLCM[DX[[i]]], {i, 1, 
              dims[[1]]}]; 
LeftDenMat = 
            DiagonalMatrix[LeftDenMat]; 
Factor[
            Simplify[{LeftDenMat, 
                LeftDenMat . x}]]
)]

LeftCoprimeMFD[x_, var_] := 
      Module[{PM1, PM2, 
          leftgcd}, 
(
{PM1, PM2} = 
            LeftMFD[x]; 
leftgcd = 
            PMLeftGCD[{PM1 , PM2}, var]; 
If[
            NumberQ[Det[leftgcd] . ConstantsList -> 
                Range[1, Length[ConstantsList]]], {PM1, PM2}, 
            PM1 = Inverse[leftgcd] . PM1; 
            PM2 = Inverse[leftgcd] . PM2]; 
{PM1, PM2} = 
            SimplifyLeftMFDCoefficients[Factor[Simplify[PM1]], 
              Factor[Simplify[PM2]], var]
)]

HighestRowDegreeCoefficientMatrix[mat_List, 
        var_]:=Module[{MatHR}, 
(
MatHR = mat; 
Do[
            MatHR[[i]] = 
              PolynomialReduceQuotients[mat[[i]], 
                var^(Max[
                        Exponent[mat[[i]], 
                          var]] //. -Infinity -> 0), var], {i, 
              1, Dimensions[
                  mat][[1]]}]; 
MatHR
)]

HighestColumnDegreeCoefficientMatrix[mat_List, var_] := 
      Module[{TMatHC}, 
(
TMatHC = 
            HighestRowDegreeCoefficientMatrix[Transpose[mat], 
              var]; 
Transpose[
            TMatHC]
)]

ColumnProperQ[mat_List, var_] := 
      Module[{numrows, numcolumns, MatrixDegree, columndegrees, 
          ColumnComplexity}, 
({numrows, numcolumns} = 
            Dimensions[mat]; 
If[numrows > numcolumns, 
            MatrixDegree = 
              Max[Exponent[Flatten[Minors[mat, Rank[mat]]], var]], 
            If[Rank[mat] == numcolumns, 
              MatrixDegree = Max[Exponent[Det[mat], var]], 
              If[Rank[HighestColumnDegreeCoefficientMatrix[mat, 
                      var]] == Min[{numrows, numcolumns}], True, 
                False]]]; 
columndegrees = 
            MatrixColumnDegrees[mat, var]; 
          ColumnComplexity = 
            Apply[Plus, columndegrees]; 
If[
            ColumnComplexity == MatrixDegree, True, 
            False]
)]

\(RowDependenceCoefficients[MTRX_List] := 
      Module[{MTRXRows, A, MProd, GeneralSol, SA, 
          a}, 
\((
MTRXRows = \(Dimensions[MTRX]\)[\([1]\)]; 
A = 
            Array[a, MTRXRows]; 
MProd = 
            A . MTRX; 
Off[
            Solve::"svars"]; 
GeneralSol = 
            Solve[MProd == 0, A]; 
On[
            Solve::"svars"]; 
SA = 
            A /. GeneralSol; 
Do[
            SA = SA /. a[i] -> 1, {i, 
              MTRXRows}]; 
Flatten[
            SA]
)\)]\)

\(ColumnDependenceCoefficients[MTRX_List] := 
      Module[{MTRXCols, A, MProd, GeneralSol, SA, 
          a}, 
\((
MTRXCols = \(Dimensions[MTRX]\)[\([2]\)]; 
A = 
            Array[a, MTRXCols]; 
MProd = 
            MTRX . Partition[A, 1]; 
Off[
            Solve::"svars"]; 
GeneralSol = 
            Solve[MProd == 0, A]; 
On[
            Solve::"svars"]; 
SA = 
            A /. GeneralSol; 
Do[
            SA = SA /. a[i] -> 1, {i, 
              MTRXCols}]; 
Flatten[
            SA]
)\)]\)

MatrixReductionToRowProper[M_List, var_] := 
      Module[{MP, MNumRows, MNumCols, MLTrans, Mhr, AR, r0, rowdeg, rd, ARS, 
          INR, RowPosr0, 
          MLr}, 
(
MP = 
            M; 
MNumRows = Dimensions[
                M][[1]]; 
MNumCols = Dimensions[
                M][[2]]; 
MLTrans = 
            IdentityMatrix[MNumRows]; 
While[
            Rank[Mhr = 
                  HighestRowDegreeCoefficientMatrix[MP, var]] ≠ 
              Min[MNumRows, 
                MNumCols], 
AR = NullSpace[
                  Transpose[
                    Mhr = HighestRowDegreeCoefficientMatrix[MP, 
                        var]]][[1]]; r0 = Max[Exponent[MP, var]]; 
            rowdeg = Array[rd, MNumRows]; 
            Do[rowdeg[[i]] = Max[Exponent[MP[[i]], var]], {i, 
                MNumRows}]; ARS = AR*var^(r0 - rowdeg); 
            INR = IdentityMatrix[MNumRows]; 
            RowPosr0 = Position[Expand[MP], var^r0][[1, 1]]; 
            MLr = ReplacePart[INR, ARS, RowPosr0]; MLTrans = MLr . MLTrans; 
            MP = Factor[Simplify[MLr . MP]]]; 
Factor[
            Simplify[{MP, MLTrans}]]
)]

MatrixReductionToColumnProper[M_List, var_] := 
      Module[{MP, MNumRows, MNumCols, MRTrans, Mhc, AC, c0, coldeg, cd, ACS, 
          INC, ColPosc0, 
          MRc}, 
(
MP = 
            M; 
MNumRows = Dimensions[
                M][[1]]; 
MNumCols = Dimensions[
                M][[2]]; 
MRTrans = 
            IdentityMatrix[MNumCols]; 
While[
            Rank[Mhc = 
                  HighestColumnDegreeCoefficientMatrix[MP, var]] ≠ 
              Min[MNumRows, 
                MNumCols], 
AC = NullSpace[
                  Mhc = HighestColumnDegreeCoefficientMatrix[MP, 
                      var]][[1]]; c0 = Max[Exponent[MP, var]]; 
            coldeg = Array[cd, MNumCols]; 
            Do[coldeg[[i]] = 
                Max[Exponent[Transpose[MP][[i]], var]], {i, 
                MNumCols}]; ACS = AC*var^(c0 - coldeg); 
            INC = IdentityMatrix[MNumCols]; 
            ColPosc0 = Position[Expand[Transpose[MP]], var^c0][[1, 
                  1]]; MRc = Transpose[ReplacePart[INC, ACS, ColPosc0]]; 
            MRTrans = MRTrans . MRc; 
            MP = Factor[Simplify[MP . MRc]]]; 
Factor[
            Simplify[{MP, MRTrans}]]
)]

ColumnProperDenominatorRightCoprimeMFD[Mat_List, var_] := 
      Module[{NR, DR, DR1, 
          DRTrans}, 
(
{NR, DR} = 
            RightCoprimeMFD[Mat, var]; 
{DR1, DRTrans} = 
            MatrixReductionToColumnProper[DR, var]; 
Factor[
            Simplify[{NR . DRTrans, DR1}]]
)]

RowProperDenominatorLeftCoprimeMFD[Mat_List, var_] := 
      Module[{DL, NL, DL1, 
          DLTrans}, 
(
{DL, NL} = 
            LeftCoprimeMFD[Mat, var]; 
{DL1, DLTrans} = 
            MatrixReductionToRowProper[DL, var]; 
Factor[
            Simplify[{DL1, DLTrans . NL}]]
)]

MatrixColumnDegrees[Mat_List, var_] := 
      Module[{NumCols, ColumnDegs, 
          cdegs}, 
(
NumCols = Dimensions[Mat][[-1]]; 
ColumnDegs = 
            Array[cdegs, NumCols]; 
Do[
            ColumnDegs[[i]] = 
              Max[Exponent[Transpose[Expand[Mat]][[i]], var]], {i, 
              NumCols}]; 
ColumnDegs
)]

MatrixRowDegrees[Mat_List, var_] := 
      Module[{NumRows, RowDegs, 
          rdegs}, 
(
NumRows = Dimensions[Mat][[1]]; 
RowDegs = 
            Array[rdegs, NumRows]; 
Do[
            RowDegs[[i]] = 
              Max[Exponent[Expand[Mat][[i]], var]], {i, 
              NumRows}]; 
RowDegs
)]

PowerVector[x_, p_] := 
      Module[{pv}, 
(
pv = {1}; 
Do[
            pv = Append[pv, x^expi], {expi, 1, 
              p}]; 
pv
)]

\(\(\( (*ADDITIONAL\ FUNCTIONS\ APPLYING\ TO\ RATIONAL\ MATRICES*) \)\(
\)\(
\)\(StrictlyProperRationalMatrixQ[mat_, var_] := 
      Module[{DD}, 
\((
If[\((TensorRank[
                    mat] != 0 && Length[mat] ≠ 0)\), 
            DD = DegDifference[mat, var]; 
            TrueQ[Cases[Flatten[DD], n_ /; n < 0] == Flatten[DD]], 
            TrueQ[0 == 1]]
)\)]\)\)\)

\(\(\( (*UPDATED\ ALGORITHM\ FUNCTIONS*) \)\(
\)\)\)

DenominatorElementsCoefficients[PolMat_List, var_, 
        ColumnUpToDegree_List: 
           Map[Max, Exponent[Transpose[PolMat], var];/
                  VectorQ[ColumnUpToDegree] === True && 
              Length[ColumnUpToDegree] === Dimensions[PolMat][[2]]]] := 
      Module[{DK}, 
(
DK = 
            CoefficientList[PolMat, var]; 
Do[
            DK[[All, ci]] = 
              Map[Append[#, 
                    ZeroVector[
                      1 + ColumnUpToDegree[[ci]] - Length[#]]] &, 
                DK[[All, ci]]], {ci, Dimensions[PolMat][[2]]}]; 
          DK = Partition[Flatten[DK], 
              Apply[Plus, 
                  ColumnUpToDegree] + Dimensions[
                    PolMat][[2]]]
)]

ComputeClassOfCompensators[Plant_, DenominatorMatrix_, var_] := 
      Module[{Dleft, Nleft, Dright, Nright, PlantRows, PlantColumns, 
          DrightColumnDegrees, mi, DenominatorMatrixDegrees, Ksi, KsiMax, 
          gwres, Dk, MekDkM, ColReducedMekDkM, ji1, ji2, ws, Ws, 
          w}, ( {Dleft, Nleft} = 
            RowProperDenominatorLeftCoprimeMFD[Plant, var]; {Nright, 
              Dright} = 
            ColumnProperDenominatorRightCoprimeMFD[Plant, var]; {PlantRows, 
              PlantColumns} = Dimensions[Plant]; 
          DrightColumnDegrees = Map[Max, Exponent[Transpose[Dright], var]]; 
          mi = Max[Flatten[Exponent[Dleft, var]]]; 
          DenominatorMatrixDegrees = 
            Map[Max, Exponent[DenominatorMatrix, var]]; 
          Map[Set[Ksi[#], (DenominatorMatrixDegrees - 
                      DrightColumnDegrees)[[#]]] &, 
            Range[PlantColumns]]; 
          KsiMax = Max[Array[Ksi, PlantColumns]]; 
gwres = 
            GWResultant[Dright, Nright, var, KsiMax + 1]; 
          Dk = DenominatorElementsCoefficients[DenominatorMatrix, var, 
              DrightColumnDegrees + KsiMax]; 
          MekDkM = VerticalBlockMatrix[{gwres, Dk}]; 
          ColReducedMekDkM = Transpose[RowReduce[Transpose[MekDkM]]]; 
          Do[parsysmat[ji1] = 
              Transpose[
                ColReducedMekDkM[[Range[(Length[Dleft] + 
                            Length[Dright]) (Ksi[ji1] + 1)], 
                    Range[Dimensions[
                            ColReducedMekDkM][[2]] - (Max[
                                Array[Ksi, Length[Dright]]] - Ksi[ji1]) 
                          Length[Dright]]]]]; 
            nsp[ji1] = NullSpace[parsysmat[ji1]]; 
            nspdim[ji1] = Length[nsp[ji1]]; 
            cumnumpar[ji1] = Apply[Plus, Map[nspdim, Range[ji1]]], {ji1, 1, 
              Length[Dright]}]; cumnumpar[0] = 0; 
          Ws = Array[ws, Length[Dright]]; 
          Do[w[ji2] = 
              LinearSolve[parsysmat[ji2], 
                  ColReducedMekDkM[[-Length[Dright] + ji2 - 1, 
                      Range[Dimensions[
                              ColReducedMekDkM][[2]] - (Max[
                                  Array[Ksi, Length[Dright]]] - Ksi[ji2]) 
                            Length[Dright]]]]] + 
                Array[t, nspdim[ji2], cumnumpar[ji2 - 1] + 1] . 
                  nsp[ji2], {ji2, 1, Length[Dright]}]; 
          Do[ws[ji3] = 
              Apply[Plus, 
                Partition[w[ji3], Length[w[ji3]]/(Ksi[ji3] + 1)]*
                  PowerVector[var, Ksi[ji3]]], {ji3, 1, PlantColumns}]; {XL, 
              YL, numofparameters} = {Transpose[Transpose[
                    Ws][[Range[PlantColumns]]]], 
              Transpose[Transpose[
                    Ws][[Range[PlantColumns + 1, 
                      PlantColumns + PlantRows]]]], 
              cumnumpar[Length[Dright]]})]

PolynomialToList[poly_, pow_Integer /; pow ≥ 0, 
        var_] := Flatten[
        Append[CoefficientList[poly, var], 
          ZeroVector[
            pow - Length[CoefficientList[poly, var]] + 
              1]]]

GWResultant[D_, N_, var_, k_Integer /; k ≥ 1] := 
      Module[{F, degCF, MkfirstBlock, 
          Mk}, 
(
F = 
            VerticalBlockMatrix[{D, N}]; 
degCF = 
            Map[Max, Exponent[Transpose[F], var]] //. -Infinity -> 
                0; 
MkfirstBlock = 
            Table[PolynomialToList[F[[i, j]], degCF[[j]] + k - 1, 
                var], {i, 1, Dimensions[F][[1]]}, {j, 
                1, Dimensions[F][[2]]}]; 
Mk = 
            Partition[
              Flatten[NestList[Map[RotateRight[#, 1] &, #, {2}] &, 
                  MkfirstBlock, k - 1]], Dimensions[F][[2]]*k + 
                Apply[Plus, degCF]]
)]

GeneralizedRe[z_] := ComplexExpand[Re[z]]
GeneralizedIm[z_] := ComplexExpand[Im[z]]
GeneralizedConjugate[w_] := ComplexExpand[Conjugate[w]]

\(\(\( (*\ 
      DEFINTION\ OF\ ALL\ PROCEDURES\ THAT\ LAUNCH\ DIALOG\ WINDOWS\ ASKING\ FOR\ DATA\ *) \)\(
\)\(
\)\( (*\ 
      The\ following\ is\ the\ definition\ of\ the\ process\ that\ asks\ for\ the\ dimensions\ of\ the\ plant\ matrix\ *) \)\(
\)\(GetPlantDimensions := 
      Module[{dims}, \((Off[Syntax::"com"]; 
          dims = InputString["Please define strictly proper plant dimensions.Input should be of the form                                          '{number of rows,number of columns}' ."]; 
          If[SyntaxQ[dims], dims = ToExpression[dims]; On[Syntax::"com"]; 
            If[\((VectorQ[dims] && Length[dims] == 2 && 
                  Apply[And, Map[IntegerQ, dims]] && 
                  Apply[And, Map[Positive, dims]])\), dims, 
              GetPlantDimensions], On[Syntax::"com"]; 
            GetPlantDimensions])\)]

 (*The\ dialog\ asking\ for\ the\ value\ of\ a\ specific\ row\ degree\ of\ the\ denominator\ matrix*) 

    KsiDefinitionDialog[i_Integer, mi_Integer] := 
      Module[{ksivalue}, \((Off[Syntax::"com"]; 
          ksivalue = 
            InputString[
              StringForm["Assign the `1``2` row degree of the denominator matrix", i, Switch[i, 1, "st", 2, "nd", 
                  3, "rd", _Integer /; i > 3, "th"]]]; 
          If[SyntaxQ[ksivalue], ksivalue = ToExpression[ksivalue]; 
            On[Syntax::"com"]; 
            If[IntegerQ[ksivalue] && ksivalue >= mi - 1, ksivalue, 
              KsiDefinitionDialog[i, mi]], On[Syntax::"com"]; 
            KsiDefinitionDialog[i, mi]])\)]

 (*\ 
      The\ following\ is\ the\ definition\ for\ the\ dialog\ box\ that\ asks\ for\ a\ complex\ root*) 


    GetComplexRoot := 
      Module[{comroot}, \((Off[Syntax::"com"]; 
          comroot = 
            InputString["Please enter root. Input should be of the form ' a+b I ' (a<0 and b real number). NOTE: Input should not contain the quotation marks"]; 
          If[SyntaxQ[comroot], comroot = ToExpression[comroot]; 
            On[Syntax::"com"]; 	
            If[NumericQ[
                comroot //. 
                  Map[# -> 1 &, Cases[comroot, _Symbol, Infinity]]], 
              If[NumericQ[GeneralizedRe[comroot]] && 
                  GeneralizedRe[comroot] ≥ 0, GetComplexRoot, 
                comroot], comroot], On[Syntax::"com"]; 
            GetComplexRoot])\)]

 (*\ 
      This\ defines\ the\ process\ that\ asks\ for\ the\ variable\ specification*) 


    GetVariableSymbol := 
      Module[{varsym}, \((Off[Syntax::"com"]; 
          varsym = 
            InputString["Specify the variable name (The symbol which should be considered as the variable of the matrix...):"]; 
If[
            SyntaxQ[varsym], varsym = ToExpression[varsym]; 
            On[Syntax::"com"]; 
            If[Head[varsym] == Symbol, varsym, GetVariableSymbol], 
            On[Syntax::"com"]; 
            GetVariableSymbol])\)]

 (*This\ defines\ the\ process\ that\ asks\ for\ the\ definition\ of\ the\ plant*) 


    GetSPPlant := 
      Module[{plant}, \((Off[Syntax::"com"]; 
          plant = InputString["Please define the strictly proper plant:"]; 
If[SyntaxQ[plant], 
            plant = ToExpression[plant]; On[Syntax::"com"]; 
            Rationalize[plant], 
            GetSPPlant])\)]

 (*MainDisplayNBObject\ INTERFACE\ FUNCTIONS\ AND\ OBJECTS*) 

    DisplayPlant[P_List, DL_List, NL_List, DR_List, 
        NR_List] := \((NotebookLocate[{MainDisplayNBObject, "Strictly Proper Plant"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
        NotebookWrite[MainDisplayNBObject, 
          Cell[BoxData[
              RowBox[{ToBoxes["P("], var, ToBoxes[")="], 
                  ToBoxes[MatrixForm[P]], "
           =", 
                  RowBox[{SubsuperscriptBox["D", "L", \(-1\)], 
                      ToBoxes["("], var, ToBoxes[")"], 
                      SubscriptBox["N", "L"], ToBoxes["("], var, 
                      ToBoxes[")="]}], 
                  SuperscriptBox[ToBoxes[MatrixForm[DL]], \(-1\)], 
                  ToBoxes[MatrixForm[NL]], "
           =", 
                  RowBox[{SubscriptBox["N", "R"], ToBoxes["("], 
                      var, ToBoxes[")"], 
                      SubsuperscriptBox["D", "R", \(-1\)], 
                      ToBoxes["("], var, ToBoxes[")="]}], 
                  ToBoxes[MatrixForm[NR]], 
                  SuperscriptBox[
                    ToBoxes[
                      MatrixForm[DR]], \(-1\)]}]], "TraditionalForm", 
            FontSize -> 16, FontFamily -> "Arial", 
            FontWeight -> "Bold", 
            CellTags -> "Strictly Proper Plant", 
            ShowCellTags -> False, Selectable -> True, 
            CellHorizontalScrolling -> True], After])\)


    DisplayCompensators[xl_List, 
        yl_List] := \((NotebookLocate[{MainDisplayNBObject, "Class Of Compensators"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
        NotebookWrite[MainDisplayNBObject, 
          Cell[BoxData[
              RowBox[{ToBoxes["C("], var, ToBoxes[")="], 
                  SuperscriptBox[ToBoxes[MatrixForm[xl]], \(-1\)], 
                  ToBoxes[MatrixForm[yl]]}]], "TraditionalForm", \ 
            FontSize\  -> \ 16, \ FontFamily\  -> \ "Arial", \ 
            FontWeight\  -> \ "Bold", 
            CellTags -> "Class Of Compensators", 
            ShowCellTags -> False, Selectable -> True, 
            CellHorizontalScrolling -> True], 
          After])\)
 (*This\ Function\ Constructs\ the\ pxm\ Plant\ Array*) 


    \ CreatePlantArray[p_Integer, 
        m_Integer] := \((\(PlantB = 
            Array[pl, {p, 
                m}]\ ;\))\)



 (*This\ Function\ Creates\ the\ Button\ Represantation\ of\ the\ {i, 
          j}\ element\ of\ the\ Plant\ Array*) 

    ButtonElement[i_Integer, j_Integer] := 
      ButtonBox[
        pl[i, j] /. 
          pl[i, j] :> 
            StyleForm[Subscript[p, StringForm["`1`,`2`", i, j]], 
                FontColor -> RGBColor[1, 0, 0]] /; 
              Head[pl[i, j]] == pl, ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> \((pl[i, j] = 
              Input[StringForm["Please define the (`1`,`2`)  element of the plant.", i, j]]; NotebookLocate[
"Define Plant"]; 
            NotebookWrite[SelectedNotebook[], 
              Cell[
                BoxData[
                  RowBox[{"(", 
                      ToBoxes[
                        ButtonElementsArray[dim1, 
                          dim2]], ")"}]], "Outline2", 
                CellTags -> \ "Define Plant", 
                ShowCellTags -> True, ShowCellBracket -> False, 
                CellMargins -> {{1, 1}, {1, 1}}, 
                CellHorizontalScrolling -> 
                  True]])\)]


 (*This\ Function\ Creates\ And\ Displays\ The\ Array\ Of\ the\ Buttons\ Representing\ The\ Elements\ of\ The\ Plant\ Array*) 


    ButtonElementsArray[dim1_Integer, dim2_Integer] := 
      GridBox[Array[ButtonElement, {dim1, dim2}], ColumnSpacings -> 0, 
          RowSpacings -> 0] // 
        DisplayForm



 (*This\ is\ the\ expression\ of\ the\ notebook\ for\ the\ definition\ of\ the\ plant\ using\ buttons*) 


    \(DefinePlantUsingBoxesNB := 
        Notebook[{Cell[
              BoxData[RowBox[{"(", 
                    ToBoxes[
                      ButtonElementsArray[dim1, 
                        dim2]], ")"}]], "Outline2", 
              CellTags -> \ "Define Plant", 
              ShowCellTags -> True, ShowCellBracket -> False, 
              CellMargins -> {{1, 1}, {1, 1}}, 
              CellHorizontalScrolling -> True], 
            Cell[BoxData[CloseDefinePlantUsingBoxesNBButton], "Outline2", 
              ShowCellBracket -> False, 
              CellMargins -> {{1, 1}, {1, 1}}, CellFrame -> True, 
              CellFrameMargins -> 2, TextAlignment -> Center, 
              Background -> \(Options[ButtonBox, Background]\)[\([1, 
                    2]\)]]}, WindowFrame -> "Palette", 
          WindowTitle -> "Please Define The Strictly Proper Plant", 
          WindowSize -> FitAll, WindowFloating -> True, 
          WindowFrameElements -> {"ResizeArea"}, 
          Visible -> False, 
          ScrollingOptions -> {PagewiseScrolling -> Inherited, 
              PagewiseDisplay -> Inherited, 
              RealTimeScrolling -> Inherited, 
              JumpScrolling -> Inherited, 
              HorizontalScrollRange -> \ 12000, 
              SpeedParameters -> 
                Inherited}];\)


 (*This\ is\ the\ definition\ of\ the\ button\ used\ to\ initiate\ the\ process\ of\ defining\ the\ plant\ using\ boxes*) 


    DefinePlantB := 
      ButtonBox["Define Plant(Boxes)", ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> \((If[
              Count[Flatten[Attributes[{dim1, dim2}]], Protected] == 0, 
              SetOptions[MainButtonsPaletteObject, Editable -> True, 
                Visible -> False]; 
              NotebookLocate[{MainDisplayNBObject, "Class Of Compensators"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
              NotebookWrite[MainDisplayNBObject, 
                Cell["", "Input", 
                  CellTags -> "Class Of Compensators", 
                  ShowCellTags -> False, Selectable -> True], 
                After]; 
              ComputedCompensator = False; {dim1, dim2} = GetPlantDimensions; 
              SetAttributes[{dim1, dim2}, Protected]; 
              PlantDefinitionNBObject = 
                NotebookPut[DefinePlantUsingBoxesNB]]; 
            NotebookCenter[PlantDefinitionNBObject]; 
            SetOptions[PlantDefinitionNBObject, 
              Visible -> 
                True])\)]

 (*This\ is\ the\ expression\ of\ the\ button\ that\ closes\ the\ "Definition of the plant using boxes" - 
        notebook\ and\ assigns\ the\ defined\ matrix\ as\ a\ strictly\ proper\ plant, if\ the\ former\ has\ been\ defined\ properly*) 


    CloseDefinePlantUsingBoxesNBButton := 
      ButtonBox["Finish", ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> \((CreatePlantArray[dim1, dim2]; 
            SetOptions[ButtonNotebook[], WindowFloating -> False]; 
            If[MatrixQ[StrictlyProperPlant] == True, 
              LastValidPlant = StrictlyProperPlant; LastValidVar = var]; 
            If[Length[Variables[PlantB]] == 1, 
              PlantBvar = \(Variables[PlantB]\)[\([1]\)], 
              PlantBvar = GetVariableSymbol]; 
            StrictlyProperPlant = Rationalize[PlantB]; var = PlantBvar; 
            StrictlyProperPlant = Factor[StrictlyProperPlant]; 
            If[Equal[StrictlyProperRationalMatrixQ[StrictlyProperPlant, var], 
                True], \((Set[AppropriatePlantData, True]; 
                KsiRowDegreesDefined = False; 
                If[Equal[Length[Dimensions[StrictlyProperPlant]], 1], 
                  Set[StrictlyProperPlant, 
                    Partition[StrictlyProperPlant, 1]]]; 
                Set[ConstantsList, 
                  DeleteCases[Variables[StrictlyProperPlant], var]]; 
                Set[{PlantRows, PlantColumns}, 
                  Dimensions[StrictlyProperPlant]]; 
                Set[{Dleft, Nleft}, 
                  RowProperDenominatorLeftCoprimeMFD[StrictlyProperPlant, 
                    var]]; Set[{Nright, Dright}, 
                  ColumnProperDenominatorRightCoprimeMFD[StrictlyProperPlant, 
                    var]]; DisplayPlant[StrictlyProperPlant, Dleft, Nleft, 
                  Dright, Nright]; 
                Set[DrightColumnDegrees, MatrixColumnDegrees[Dright, var]]; 
                Set[DleftRowDegrees, MatrixRowDegrees[Dleft, var]]; 
                Set[n, Apply[Plus, DleftRowDegrees]]; 
                Set[mi, Max[DleftRowDegrees]]; 
                AppropriateDenominatorMatrix = False; 
                NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData[{"The plant has changed. The closed loop system denominator matrix should be  redefined."}], 
                    CellTags -> "Closed Loop System Denominator Matrix", 
                    ShowCellTags -> False, Selectable -> True], After]; 
                NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix Row Powers"}]; 
                SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData[{"The plant has changed. The closed loop system denominator matrix row powers should be redefined."}], 
                    CellTags -> "Closed Loop System Denominator Matrix Row Powers", ShowCellTags -> False, Selectable -> True], After])\), 
              If[StrictlyProperRationalMatrixQ[LastValidPlant, 
                    LastValidVar] == True, 
                StrictlyProperPlant = LastValidPlant; var = LastValidVar, 
                NotebookLocate[{MainDisplayNBObject, "Strictly Proper Plant"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData["The Plant Definition is Invalid.Please Redefine the system's transfer matrix."], 
                    CellTags -> "Strictly Proper Plant", 
                    ShowCellTags -> False, Selectable -> True], 
                  After]]]; ClearAttributes[{dim1, dim2}, Protected]; 
            NotebookClose[ButtonNotebook[]]; 
            SetOptions[MainButtonsPaletteObject, Visible -> True, 
              WindowFloating -> True, 
              Editable -> 
                False])\)]

 (*This\ is\ the\ definition\ of\ the\ button\ used\ to\ textually\ define\ the\ plant*) 


    DefinePlantT := 
      ButtonBox[
        RowBox[{"Define", " ", "Plant", "(Standard)"}], 
        ButtonFunction :> 
\((Off[
              MessageName[Syntax, "sntxi"]]; 
            Off[MessageName[Flatten, "normal"]]; 
            NotebookLocate[{MainDisplayNBObject, "Class Of Compensators"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
            NotebookWrite[MainDisplayNBObject, 
              Cell["", "Input", 
                CellTags -> "Class Of Compensators", 
                ShowCellTags -> False, Selectable -> True], After]; 
            ComputedCompensator = False; 
            If[MatrixQ[StrictlyProperPlant] == True, 
              LastValidPlant = StrictlyProperPlant; 
              LastValidVar = var]; 
Set[
              StrictlyProperPlant, GetSPPlant]; 
            If[Equal[Length[Variables[StrictlyProperPlant]], 1], 
              Set[var, Part[Variables[StrictlyProperPlant], 1]], 
              Set[var, GetVariableSymbol]]; 
            Set[StrictlyProperPlant, Factor[StrictlyProperPlant]]; 
            If[Equal[StrictlyProperRationalMatrixQ[StrictlyProperPlant, var], 
                True], \((Set[AppropriatePlantData, True]; 
                If[Equal[Length[Dimensions[StrictlyProperPlant]], 1], 
                  Set[StrictlyProperPlant, 
                    Partition[StrictlyProperPlant, 1]]]; 
                Set[ConstantsList, 
                  DeleteCases[Variables[StrictlyProperPlant], var]]; 
                Set[{PlantRows, PlantColumns}, 
                  Dimensions[StrictlyProperPlant]]; 
                Set[{Dleft, Nleft}, 
                  RowProperDenominatorLeftCoprimeMFD[StrictlyProperPlant, 
                    var]]; 
                Set[{Nright, Dright}, 
                  ColumnProperDenominatorRightCoprimeMFD[StrictlyProperPlant, 
                    var]]; DisplayPlant[StrictlyProperPlant, Dleft, Nleft, 
                  Dright, Nright]; 
                Set[DrightColumnDegrees, MatrixColumnDegrees[Dright, var]]; 
                Set[DleftRowDegrees, MatrixRowDegrees[Dleft, var]]; 
                Set[n, Apply[Plus, DleftRowDegrees]]; 
                Set[mi, 
                  Max[DleftRowDegrees]] (*\(If\)\([\)\(MatrixQ[
                        DenominatorMatrix] && 
                      Exponent[\((Range[
                                  1, \(Dimensions[
                                      DenominatorMatrix]\)[\([1]\)]]/
                                Range[
                                  1, \(Dimensions[
                                      DenominatorMatrix]\)[\([1]\)]])\) . 
                            DenominatorMatrix, var] == 
                        DrightColumnDegrees + mi - 1, 
                    AppropriateDenominatorMatrix = True, \)*) ; 
                AppropriateDenominatorMatrix = False; 
                KsiRowDegreesDefined = False; 
                NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData[{"The plant has changed. The closed loop system denominator matrix should be  redefined."}], 
                    CellTags -> "Closed Loop System Denominator Matrix", 
                    ShowCellTags -> False, Selectable -> True], 
                  After] (*]*) ; 
                NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix Row Powers"}]; 
                SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData[{"The plant has changed. The closed loop system denominator matrix  row powers values should be redefined."}], 
                    CellTags -> "Closed Loop System Denominator Matrix Row Powers", ShowCellTags -> False, Selectable -> True], After])\), 
              If[StrictlyProperRationalMatrixQ[LastValidPlant, 
                    LastValidVar] == True, 
                StrictlyProperPlant = LastValidPlant; var = LastValidVar, 
                NotebookLocate[{MainDisplayNBObject, "Strictly Proper Plant"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData["The Plant Definition is Invalid.Please Redefine the system's transfer matrix."], 
                    CellTags -> "Strictly Proper Plant", 
                    ShowCellTags -> False, Selectable -> True], 
                  After]]]; 
            SetOptions[MainButtonsPaletteObject, Visible -> True, 
              WindowFloating -> True, Editable -> False])\), 
        ButtonEvaluator -> Automatic, 
        Active -> 
          True]

 (*This\ is\ the\ definition\ of\ the\ notebook\ that\ is\ launched\ in\ order\ to\ define\ the\ denominator\ matrix\ row\ powers*) 

    \)\)\)

KsiDefinitionNB := 
      Notebook[{Cell[
            TextData[{"Provide the values of the row powers of the closed \
loop system denominator matrix ", 
                Cell[RowBox[SubscriptBox["D", "C"]]], "(", 
                var, ")", ".", "\n Row powers MUST NOT be less than \
μ-1 = ", mi - 1, "."}], TextAlignment -> Center, 
            ShowCellBracket -> False, FontSize -> 16, 
            FontWeight -> "Bold"], 
Cell[
            BoxData[RowBox[{ToBoxes[
                    Array["ξ", {PlantColumns}] /. "ξ"[
                          i_] -> Subscript["ξ", i]], 
                  ToBoxes["="], ToBoxes["{"], 
                  ToBoxes[
                    RowBox[Array[KsiDefinitionButton[#] &, {PlantColumns}]] // 
                      DisplayForm], 
                  ToBoxes["}"]}]], "TraditionalForm", 
            FontSize -> 14, FontWeight -> "Bold", 
            FontFamily -> "Arial", CellHorizontalScrolling -> True, 
            CellTags -> "Closed Loop System Denominator Matrix Row \
Powers", ShowCellTags -> True, ShowCellBracket -> False, 
            Editable -> False], 
          Cell[TextData[""], ShowCellBracket -> False], 
          Cell[BoxData[ToBoxes[CloseKsiDefinitionNBObjectButton]], 
            TextAlignment -> Center, ShowCellBracket -> False, 
            Editable -> False, FontWeight -> "Bold", 
            CellHorizontalScrolling -> False]}]

\(KsiDefinitionButton[ri_Integer] := 
      ButtonBox[
          Ksi[ri] /. 
            Ksi[ri] :> 
              Subscript["ξ", ri] /; Head[Ksi[ri]] == Ksi, 
          Active -> True, ButtonEvaluator -> Automatic, 
          ButtonFunction :> \((Ksi[ri] = 
                KsiDefinitionDialog[ri, 
                  mi] (*\(;\)\(refresh\ notebook\ cell\ with\ array\)*) ; 
              NotebookLocate[{KsiDefinitionNBObject, "Closed Loop System Denominator Matrix Row Powers"}]; 
              SelectionMove[SelectedNotebook[], All, Cell]; 
              NotebookWrite[SelectedNotebook[], 
                Cell[BoxData[
                    RowBox[{ToBoxes[
                          Array["ξ", {PlantColumns}] /. "ξ"[
                                i_] -> Subscript["ξ", i]], 
                        ToBoxes["="], ToBoxes["{"], 
                        ToBoxes[
                          RowBox[
                              Array[KsiDefinitionButton[#] &, {PlantColumns}]] // DisplayForm], ToBoxes["}"]}]], "TraditionalForm", 
                  CellTags -> "Closed Loop System Denominator Matrix Row Powers", ShowCellTags -> True, ShowCellBracket -> False, 
                  FontSize -> 14, FontFamily -> "Arial", 
                  FontWeight -> "Bold", 
                  CellHorizontalScrolling -> True]])\)] // 
        DisplayForm\)

\(\(\(
\)\( (*Definition\ of\ the\ button\ that\ closes\ the\ denominator\ Row\ Powers\ definition\ notebook*) \)\(\ \)\(
\)\)\)

\(CloseKsiDefinitionNBObjectButton := 
      ButtonBox["Close Window", Active -> True, 
          ButtonEvaluator -> Automatic, 
          ButtonFunction :> \((If[
                Count[Map[IntegerQ[#] &, Map[Ksi, Range[PlantColumns]]], 
                    True] == PlantColumns, KsiRowDegreesDefined = True; 
                AppropriateDenominatorMatrix = False; 
                ComputedCompensator = False; 
                NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix Row Powers"}]; 
                SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[BoxData[
                      RowBox[{ToBoxes[
                            Array["ξ", 
                                PlantColumns] /. "ξ"[i_] -> 
                                Subscript["ξ", i]], "=", 
                          ToBoxes[
                            Map[Ksi, 
                              Range[PlantColumns]]]}]], "TraditionalForm", FontSize -> 16, FontFamily -> "Arial", 
                    FontWeight -> "Bold", 
                    CellHorizontalScrolling -> True, 
                    ShowCellTags -> False, 
                    CellTags -> "Closed Loop System Denominator Matrix Row Powers", Selectable -> False, ShowCellBracket -> False]]; 
                NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData[{"The closed loop system denominator matrix row powers have been redefined. The closed loop system denominator matrix should also be redefined."}], 
                    CellTags -> "Closed Loop System Denominator Matrix", 
                    ShowCellTags -> False, Selectable -> True], After]; 
                NotebookLocate[{MainDisplayNBObject, "Class Of Compensators"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData[{""}], 
                    CellTags -> "Class Of Compensators", 
                    ShowCellTags -> False, Selectable -> True], After], 
                KsiRowDegreesDefined = False; 
                AppropriateDenominatorMatrix = False; 
                ComputedCompensator = False; 
                NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix Row Powers"}]; 
                SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData["The values of the row powers of the closed loop system denominator matrix have not been provided."], 
                    ShowCellTags -> False, 
                    CellTags -> "Closed Loop System Denominator Matrix Row Powers", Selectable -> False, ShowCellBracket -> False]]; 
                NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData[{""}], 
                    CellTags -> "Closed Loop System Denominator Matrix", 
                    ShowCellTags -> False, Selectable -> True], After]; 
                NotebookLocate[{MainDisplayNBObject, "Class Of Compensators"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData[{""}], 
                    CellTags -> "Class Of Compensators", 
                    ShowCellTags -> False, Selectable -> True], After]]; 
              NotebookClose[KsiDefinitionNBObject]; 
              SetOptions[MainButtonsPaletteObject, Visible -> True, 
                WindowFloating -> True, Editable -> False])\)] // 
        DisplayForm\)

DefineKsiRowDegreesButton := 
      ButtonBox["Define Denominator Matrix Row Powers", 
        Active -> True, ButtonEvaluator -> Automatic, 
        ButtonFunction :> (If[AppropriatePlantData === True, 
              SetOptions[MainButtonsPaletteObject, Editable -> True, 
                WindowFloating -> False, Visible -> False]; 
              ClearAll[Ksi]; KsiRowDegreesDefined = False; 
              KsiDefinitionNBObject = 
                NotebookPut[KsiDefinitionNB] , NotebookPut[
                  Notebook[{Cell[
                        TextData["There is no valid definition for the \
plant. Please define the plant first."]], 
                      Cell[BoxData[
                          ButtonBox[
                            ToBoxes[
                              StyleForm[StringForm["Close"], 
                                FontWeight -> "Bold"]], 
                            ButtonEvaluator -> Automatic, 
                            Active -> True, 
                            ButtonFunction :> (NotebookClose[
                                  ButtonNotebook[]]; 
                                SetOptions[MainButtonsPaletteObject, 
                                  Visible -> True, 
                                  WindowFloating -> True, 
                                  Editable -> False])]]]}, 
                    TextAlignment -> 0, ShowCellBracket -> False, 
                    WindowFrame -> "Palette", 
                    WindowFrameElements -> {}, 
                    WindowElements -> {}, Editable -> False, 
                    Background -> Options[ButtonBox, 
                          Background][[1, 2]], 
                    ScrollingOptions -> {PagewiseScrolling -> True, 
                        PagewiseDisplay -> Inherited, 
                        RealTimeScrolling -> Inherited, 
                        JumpScrolling -> Inherited, 
                        HorizontalScrollRange -> Inherited, 
                        SpeedParameters -> Inherited}, 
                    WindowSize -> {Automatic, FitAll}, 
                    WindowTitle -> "Closed loop system denominator row \
powers"]];])]

DisplayGWResultant:=ButtonBox["Display Resultant",Active -> True,ButtonEvaluator -> Automatic,ButtonFunction:>If[KsiRowDegreesDefined === True,SetOptions[MainButtonsPaletteObject, 
                  Editable -> True, WindowFloating -> False, 
                  Visible -> False]; 
                DisplayResultantNBObject = 
                  NotebookCenter[NotebookPut[DisplayResultantNB]],NotebookPut[Notebook[{Cell[
                              TextData["There are no valid definitions for \
the closed loop system denominator matrix row powers. Please define the \
closed loop system denominator matrix row powers first."]],Cell[BoxData[ButtonBox[ToBoxes[StyleForm["Close", 
                                        FontWeight -> "Bold"]],ButtonEvaluator -> 
                                      Automatic,Active -> True,ButtonFunction :> (NotebookClose[ButtonNotebook[]]; SetOptions[MainButtonsPaletteObject, 
                                        Visible -> True, 
                                        WindowFloating -> True, 
                                        Editable -> False])]]]},TextAlignment -> 0,ShowCellBracket -> False,WindowFrame -> "Palette",WindowFrameElements -> {},WindowElements -> {},Editable -> False,Background -> Options[ButtonBox, 
                              Background][[1, 
                            2]],ScrollingOptions -> {PagewiseScrolling -> True, PagewiseDisplay -> Inherited, 
                            RealTimeScrolling -> Inherited, 
                            JumpScrolling -> Inherited, 
                            HorizontalScrollRange -> Inherited, 
                            SpeedParameters -> Inherited},WindowSize -> {Automatic, FitAll},WindowTitle -> "Generalized Wolovich \
Resultant"]];]]

DisplayResultantNB:=Notebook[{Cell[
                TextData[{"The generalized Wolovich Resultant ", 
                    Cell[BoxData[
                        FormBox[SubscriptBox["M", "ek"], 
                          TraditionalForm]]]}], TextAlignment -> Center, 
                ShowCellBracket -> False, FontSize -> 18, 
                FontWeight -> "Bold"],Cell["", ShowCellBracket -> False],Cell[BoxData[ButtonBox[ToBoxes[\(StyleForm["Close", "StandardForm", FontWeight -> "Bold", TextAlignment -> Center, 
                              FontSize -> 14]\)],ButtonEvaluator -> Automatic,Active -> True,ButtonFunction :> (NotebookClose[
                              ButtonNotebook[]]; 
                            SetOptions[MainButtonsPaletteObject, 
                              Visible -> True, 
                              WindowFloating -> True, 
                              Editable -> False])]],TextAlignment -> Center,ShowCellBracket -> False],Cell["", ShowCellBracket -> False],Cell[
                BoxData[
                  RowBox[{FormBox["k=", TraditionalForm], 
                      Max[Ksi /@ Range[PlantColumns]] + 1, ",", 
                      FormBox[
                        SubscriptBox["M", 
                          ToBoxes[
                            StringForm["e`1`", 
                              Max[Ksi /@ Range[PlantColumns]] + 
                                1]]], "TraditionalForm"] , 
                      FormBox["∈", TraditionalForm], 
                      FormBox[
                        SuperscriptBox["ℝ", 
                          ToBoxes[
                            Dimensions[
                                GWResultant[Dright, Nright, var, 
                                  Max[Ksi /@ Range[PlantColumns]] + 
                                    1]] //. {r_, c_} -> 
                                StringForm["`1`×`2`", r, c]]], 
                        TraditionalForm]}]], FontSize -> 20, 
                FontWeight -> "Normal", ShowCellBracket -> False, 
                TextAlignment -> Center],Cell["", ShowCellBracket -> False],Cell[
                BoxData[
                  RowBox[{Cell[
                        BoxData[
                          FormBox[
                            SubscriptBox["M", 
                              ToBoxes[
                                StringForm["e`1`", 
                                  Max[Ksi /@ Range[PlantColumns]] + 
                                    1]]], "TraditionalForm"]], 
                        FontSize -> 18], 
                      Cell[BoxData[FormBox["=", "TraditionalForm"]], 
                        FontSize -> 18], 
                      FormBox[
                        ToBoxes[
                          MatrixForm[
                            GWResultant[Dright, Nright, var, 
                              Max[Ksi /@ Range[PlantColumns]] + 
                                1]]], "TraditionalForm"]}]], 
                TextAlignment -> Center, ShowCellBracket -> False, 
                FontSize -> 14]},WindowFrameElements -> {},WindowSize -> {2500, FitAll},WindowTitle -> "Generalized Wolovich Resultant",WindowFrame -> "Palette"]

\(\(\(
\)\( (*This\ is\ the\ definition\ of\ the\ button\ that\ launches\ the\ process\ of\ selecting\ the\ polynomial\ elemenets\ of\ the\ 
closed\ loop\ denominator\ matrix*) \)\)\)

\(\(\(
\)\(DefineDenominatorMatrix := 
      ButtonBox[
        RowBox[{"Define", " ", "Denominator", " ", "Matrix"}], 
        ButtonFunction :> 
          If[KsiRowDegreesDefined == False, 
            NotebookPut[
              Notebook[{Cell[
                    TextData["The closed loop system denominator matrix row powers need to be defined first"]], 
                  Cell[BoxData[
                      ButtonBox[
                        ToBoxes[
                          StyleForm[StringForm["Close"], 
                            FontWeight -> "Bold"]], 
                        ButtonEvaluator -> Automatic, 
                        Active -> True, 
                        ButtonFunction :> \((NotebookClose[
                              ButtonNotebook[]]; 
                            SetOptions[MainButtonsPaletteObject, 
                              Visible -> True, 
                              WindowFloating -> True, 
                              Editable -> False])\)]]]}, 
                TextAlignment -> 0, ShowCellBracket -> False, 
                WindowFrame -> "Palette", WindowFrameElements -> {}, 
                WindowElements -> {}, Editable -> False, 
                Background -> \(Options[ButtonBox, Background]\)[\([1, 
                      2]\)], ScrollingOptions -> {PagewiseScrolling -> True, PagewiseDisplay -> Inherited, 
                    RealTimeScrolling -> Inherited, 
                    JumpScrolling -> Inherited, 
                    HorizontalScrollRange -> Inherited, 
                    SpeedParameters -> Inherited}, 
                WindowSize -> {Automatic, FitAll}, 
                WindowTitle -> "Closed Loop System Denominator Definition"]], 
            If[Not[AppropriatePlantData], 
              CompoundExpression[
                NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix"}], SelectionMove[MainDisplayNBObject, All, Cell], 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData["The Plant has not been properly defined.Please define the strictly proper plant first."], 
                    CellTags -> "Closed Loop System Denominator Matrix", 
                    ShowCellTags -> False, Selectable -> True], After]], 
              NotebookLocate[{MainDisplayNBObject, "Class Of Compensators"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
              NotebookWrite[MainDisplayNBObject, 
                Cell["", "Input", 
                  CellTags -> "Class Of Compensators", 
                  ShowCellTags -> False, Selectable -> True], 
                After]; ComputedCompensator = False; 
              CompoundExpression[Set[PolynomialsIndex, 1], 
                Set[PolynomialsNumber, PlantColumns], 
                Set[PolynomialsList, 
                  Times[Range[1, PolynomialsNumber], 
                    Power[Range[1, PolynomialsNumber], \(-1\)]]], 
                Set[NumberOfRoots, ZeroVector[PolynomialsNumber]], 
                Set[DkPolynomialsDegrees, 
                  Map[Plus[DrightColumnDegrees[\([#]\)], Ksi[#]] &, 
                    Range[PlantColumns]]], 
                SetOptions[MainButtonsPaletteObject, Editable -> True, 
                  Visible -> False], 
                ComplexPlaneNBObject = NotebookPut[ComplexPlaneNB], 
                NotebookCenter[ComplexPlaneNBObject], 
                RootsAssignmentNBObject = NotebookPut[RootsAssignmentNB], 
                DisplayPolynomial[PolynomialsIndex, var], 
                DisplayRootsRemaining[PolynomialsIndex]]]], 
        ButtonEvaluator -> Automatic, Active -> True]\)\)\)

\(\(\( (*This\ is\ the\ definition\ of\ the\ button\ that\ exits*) \)\(
\)\(ExitApp := 
      ButtonBox["Exit", ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> \((Map[
              NotebookClose[#] &, {MainDisplayNBObject, 
                MainButtonsPaletteObject, ComplexPlaneNBObject, 
                RootsAssignmentNBObject, 
RootModificationNBObject, 
                PlantDefinitionNBObject, HelpNBObject}]; 
            Clear["Compensators`*"]; 
            Remove["Compensators`*"])\)]\)\)\)

ComputeCompensators := 
      ButtonBox[RowBox[{"Compute", " ", "Compensators"}], 
        ButtonFunction :> (If[
              And[AppropriatePlantData, AppropriateDenominatorMatrix], 
              CompoundExpression[{XL, 
                    YL} = ComputeClassOfCompensators[StrictlyProperPlant, 
                      DenominatorMatrix, var][[Range[2]]], 
                ComputedCompensator = True, 
                Set[TDXL, 
                  ReplaceAll[XL, t[Pattern[x, Blank[]]] -> Subscript[t, x]]], 
                Set[TDYL, 
                  ReplaceAll[YL, t[Pattern[x, Blank[]]] -> Subscript[t, x]]], 
                DisplayCompensators[TDXL, TDYL]], 
              CompoundExpression[
                NotebookLocate[{MainDisplayNBObject, "Class Of Compensators\
"}], SelectionMove[MainDisplayNBObject, All, Cell], 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData["The Plant or/and the Denominator Matrix \
definitions are invalid, or the Plant has changed and the Denominator should \
be redefined ."], CellTags -> "Class Of Compensators", 
                    ShowCellTags -> False, Selectable -> True], 
                  After]]]; 
            SetOptions[MainButtonsPaletteObject, Editable -> False, 
              WindowFloating -> False]; 
            SetOptions[MainButtonsPaletteObject, Visible -> True, 
              WindowFloating -> True, Editable -> False]), 
        ButtonEvaluator -> Automatic, 
        Active -> True]

ParametersValuesButton := 
      ButtonBox["Parameters Values", ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> (SetOptions[MainButtonsPaletteObject, 
              Editable -> True, Visible -> False]; 
            If[VectorQ[ParametersValuesArray], ClearAll[parval]]; 
            If[ComputedCompensator == 
                  True && ComputeClassOfCompensators[StrictlyProperPlant, 
                      DenominatorMatrix, var][[3]] ≠ 0, 
              ParametersValuesArray = 
                Array[parval, ComputeClassOfCompensators[
                      StrictlyProperPlant, DenominatorMatrix, 
                      var][[3]]]; 
              NotebookCenter[
                ParametersValuesNBObject = NotebookPut[ParametersValuesNB]], 
              NotebookPut[
                Notebook[{Cell[
                      TextData["There are no independent parameters in the \
expression of the class of compensators or the class has not been computed \
yet."]], Cell[BoxData[
                        ButtonBox[
                          ToBoxes[
                            StyleForm[StringForm["Close"], 
                              FontWeight -> "Bold"]], 
                          ButtonEvaluator -> Automatic, 
                          Active -> True, 
                          ButtonFunction :> (NotebookClose[
                                ButtonNotebook[]]; 
                              SetOptions[MainButtonsPaletteObject, 
                                Visible -> True, 
                                WindowFloating -> True, 
                                Editable -> False])]]]}, 
                  TextAlignment -> 0, ShowCellBracket -> False, 
                  WindowFrame -> "Palette", 
                  WindowFrameElements -> {}, WindowElements -> {}, 
                  Editable -> False, 
                  Background -> Options[ButtonBox, Background][[1, 
                        2]], 
                  ScrollingOptions -> {PagewiseScrolling -> True, 
                      PagewiseDisplay -> Inherited, 
                      RealTimeScrolling -> Inherited, 
                      JumpScrolling -> Inherited, 
                      HorizontalScrollRange -> Inherited, 
                      SpeedParameters -> Inherited}, 
                  WindowSize -> FitAll, 
                  WindowTitle -> "Independent Parameters \
Values"]]])]

ParameterBox[i_] := 
      ButtonBox[
        If[NumericQ[parval[i]], parval[i], SubscriptBox["t", i]] // 
          TraditionalForm, ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> (parval[i] = GetParameterValue[i]; 
            RefreshParametersValuesNB)]

\(\(\(
\)\(GetParameterValue[i_Integer] := 
      Module[{pv}, \((Off[Syntax::"com"]; 
          pv = InputString[
              StringForm["Please define the `1``2`  independent parameter (The value should be any real number) .", i, 
                Switch[i, 1, "st", 2, "nd", 3, "rd", 
                  x_Integer /; x > 3, "th"]]]; 
          If[SyntaxQ[pv], pv = ToExpression[pv]; On[Syntax::"com"]; 
            If[NumericQ[pv] && Im[pv] == 0, pv, GetParameterValue[i]], 
            On[Syntax::"com"]; GetParameterValue[i]])\)]\)\)\)

\(ParametersValuesNB := 
      Notebook[{Cell[
            BoxData[RowBox[{"T", "=", "(", 
                  ToBoxes[
                    RowBox[Array[ParameterBox[#] &, 
                          Dimensions[ParametersValuesArray]]] // 
                      DisplayForm], ")", " "}]], "TraditionalForm", FontSize -> 16, FontWeight -> "Bold", 
            CellTags -> "Parameters Values", 
            CellHorizontalScrolling -> True], 
          Cell[BoxData[
              RowBox[{ToBoxes["C("], var, ToBoxes[")="], 
                  SuperscriptBox[ToBoxes[MatrixForm[TDXL]], \(-1\)], 
                  ToBoxes[
                    MatrixForm[TDYL]], ""}]], "TraditionalForm", 
            FontFamily -> "Arial", FontSize -> 16, 
            FontWeight -> "Bold", CellTags -> "Compensator", 
            ShowCellTags -> True, CellHorizontalScrolling -> True], 
          Cell[BoxData[
              ButtonBox["Finish", ButtonEvaluator -> Local, 
                Active -> "True", 
                ButtonFunction :> \((NotebookClose[
                      ButtonNotebook[]]; 
                    SetOptions[MainButtonsPaletteObject, 
                      Visible -> True, WindowFloating -> True, 
                      Editable -> False])\)]], FontSize -> 12, 
            FontWeight -> "Bold", CellHorizontalScrolling -> False, 
            TextAlignment -> 0, 
            Background -> \(Options[ButtonBox, Background]\)[\([1, 
                  2]\)], CellMargins -> {{0, 0}, {1, Inherited}}]}, 
        WindowTitle -> "Computing specific members of the class of closed loop system denominator assigning compensators by assigning values to the independent parameters", ShowCellBracket -> False\ , 
        WindowSize -> {2500, 2500}, WindowFrameElements -> {}, 
        ScrollingOptions -> {PagewiseScrolling -> Inherited, 
            PagewiseDisplay -> Inherited, 
            RealTimeScrolling -> Inherited, 
            JumpScrolling -> Inherited, 
            HorizontalScrollRange -> 29500, 
            SpeedParameters -> Inherited}]\)

\(\(\(RefreshParametersValuesNB := \((NotebookLocate[{ParametersValuesNBObject, "Parameters Values"}]; 
        SelectionMove[SelectedNotebook[], All, Cell]; 
        NotebookWrite[SelectedNotebook[], 
          Cell[BoxData[
              RowBox[{"T", "=", "(", 
                  ToBoxes[
                    RowBox[Array[ParameterBox[#] &, 
                          Dimensions[ParametersValuesArray]]] // 
                      DisplayForm], ")", " "}]], "TraditionalForm", FontSize -> 16, FontWeight -> "Bold", 
            CellTags -> "Parameters Values", 
            CellHorizontalScrolling -> True], After]; 
        If[Apply[And, Map[NumericQ, Flatten[ParametersValuesArray]]] == 
            True, {CXL, CYL} = 
            Collect[Expand[
                Simplify[{XL, YL} //. 
                    Flatten[
                      Table[t[i] -> parval[i], {i, 
                          Length[ParametersValuesArray]}]]]], var]; 
          NotebookLocate[{ParametersValuesNBObject, "Compensator"}]; 
          SelectionMove[SelectedNotebook[], All, Cell]; 
          NotebookWrite[SelectedNotebook[], 
            Cell[BoxData[
                RowBox[{ToBoxes["C("], var, 
                    ToBoxes[")="], SuperscriptBox[
                      ToBoxes[
                        MatrixForm[CXL]], \(-1\)], 
ToBoxes[
                      MatrixForm[
                        CYL]], "
           =", ToBoxes[MatrixForm[
                        Rationalize[
                          Collect[Expand[Simplify[Inverse[CXL] . CYL]], 
                            var]]]]}]], "TraditionalForm", 
              FontFamily -> "Arial", FontSize -> 16, 
              FontWeight -> "Bold", CellTags -> "Compensator", 
              ShowCellTags -> True, 
              CellHorizontalScrolling -> True], After]])\)\)\(
\)
    \) (*This\ is\ the\ button\ that\ displays\ the\ help\ notebook*) \)
HelpNBButton := 
      ButtonBox["Help", ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> (HelpNBObject = 
              NotebookOpen["Help2.nb"])]

\(\(\(ComplexForm[
        x_List] := 
\((If[Length[x] == 2 && VectorQ[x], 
          x[\([1]\)] + 
            x[\([2]\)]*
              I, "Error:Input should be a vector of the form '{Rez,Imz}'"])\)\)\(
\)
    \)\)

RoundAtDigit[x_, y_Integer] := Round[x*10^(-y)]*10^y

\(\(\( (*DIORTHOSI*) \)\(
\)\(ObtainComplexFromSelectedCoordinates := \((GetCoordinates = NotebookRead[ComplexPlaneNBObject]; 
If[
          StringQ[GetCoordinates], 
          CoordinatesAsList = 
            N[RoundAtDigit[ToExpression[GetCoordinates], \(-3\)]], 
          CoordinatesAsList = 
            N[RoundAtDigit[GetCoordinates, \(-3\)]]])\)\)\)\)

\(\(\(
\)\(DisplayComplex[x_List] := \((ComplexRoot = ComplexForm[x]; 
        NotebookLocate[{ComplexPlaneNBObject, "Complex"}]; 
        SelectionMove[ComplexPlaneNBObject, All, Cell, 
          AutoScroll -> False]; 
        NotebookWrite[ComplexPlaneNBObject, 
          Cell[BoxData[
              RowBox[{"z = ", 
                  ToBoxes[
                    If[NumericQ[ComplexRoot], 
                      NumberForm[N[ComplexRoot, 17], 16], 
                      Rationalize[ComplexRoot]]], "=", 
                  ToBoxes[
                    Rationalize[ComplexRoot]]}]], "TraditionalForm", 
            FontWeight -> "Bold", CellTags -> "Complex", 
            ShowCellTags -> True, Selectable -> False, 
            ShowCellBracket -> False], After]; 
        NotebookLocate[{ComplexPlaneNBObject, "Cplot"}]; 
        SelectionMove[ComplexPlaneNBObject, Previous, Cell])\)\)\)\)

\(DisplayPolynomial[Pol_, 
        var_] := 
\((NotebookLocate[{ComplexPlaneNBObject, "Polynomial"}]; 
        SelectionMove[ComplexPlaneNBObject, All, Cell, 
          AutoScroll -> False]; 
        NotebookWrite[ComplexPlaneNBObject, 
          Cell[BoxData[
              RowBox[{SubscriptBox["d", PolynomialsIndex], 
                  ToBoxes["("], var, ToBoxes[")"], "=", 
                  ToBoxes[PolynomialsList[\([PolynomialsIndex]\)]], "=", 
                  ToBoxes[
                    Collect[Expand[PolynomialsList[\([PolynomialsIndex]\)]], 
                      var]]}]], "TraditionalForm", 
            FontWeight -> "Bold", CellTags -> "Polynomial", 
            ShowCellTags -> True, Selectable -> False, 
            ShowCellBracket -> False], After]; 
        NotebookLocate[{ComplexPlaneNBObject, "Cplot"}]; 
        SelectionMove[ComplexPlaneNBObject, Previous, Cell])\)\)

\(DisplayRootsRemaining[
        PolIndx_Integer] := 
\((RootsRemaining = 
          DkPolynomialsDegrees[\([PolIndx]\)] - 
            NumberOfRoots[\([PolIndx]\)]; 
NotebookLocate[{ComplexPlaneNBObject, "Roots Remaining"}]; 
SelectionMove[ComplexPlaneNBObject, All, 
          Cell, AutoScroll -> False]; 
NotebookWrite[
          ComplexPlaneNBObject, 
          Cell[BoxData[
              RowBox[{"Roots remaining to be specified for the full definition of ", SubscriptBox["d", PolIndx], ToBoxes["("], var, 
                  ToBoxes[") :"], 
                  RootsRemaining}]], "TraditionalForm", 
            FontWeight -> Bold, CellTags -> "Roots Remaining", 
            ShowCellTags -> True, ShowCellBracket -> False], 
          After]; NotebookLocate[{ComplexPlaneNBObject, "Cplot"}]; 
        SelectionMove[ComplexPlaneNBObject, Previous, 
          Cell]
)\)\)

StatusMessage[
        msg_Cell] := (NotebookLocate[{ComplexPlaneNBObject, "Status"}]; 
        SelectionMove[ComplexPlaneNBObject, All, Cell, 
          AutoScroll -> False]; 
NotebookWrite[
          ComplexPlaneNBObject, msg, After]; 
        NotebookLocate[{ComplexPlaneNBObject, "Cplot"}]; 
        SelectionMove[ComplexPlaneNBObject, Previous, Cell])

CreateRootMultiplesArray[
        x_List?VectorQ] := (Array[(ComplexForm[{10^(#1 - 3), 
                    10^(#2 - 3)}*x]) &, {5, 5}])

RootMultiplesGridBox[rootmultiples_?MatrixQ] := 
      GridBox[Array[
            ButtonBox[rootmultiples[[#1, #2]], Active -> True, 
                ButtonEvaluator -> Automatic, 
                ButtonFunction :> (LastRootSelection = 
                      CoordinatesAsList; 
                    CoordinatesAsList = {GeneralizedRe[
                          rootmultiples[[#1, #2]]], 
                        GeneralizedIm[rootmultiples[[#1, #2]]]}; 
                    RefreshRootModificationNB)] &, {5, 5}], 
          ColumnSpacings -> 0, RowSpacings -> 0] // 
        DisplayForm

RefreshRootModificationNB:=(NotebookLocate[{RootModificationNBObject, "Current Root \
Selection"}];MoveSelection[RootModificationNBObject, All, Cell];NotebookWrite[RootModificationNBObject, 
              Cell[BoxData[
                  RowBox[{"z=", 
                      ToBoxes[
                        ComplexForm[
                          CoordinatesAsList]], "                  ", 
                      GridBox[{{UndoButton}, {ResetButton}}]}]], 
                CellTags -> "Current Root Selection", 
                TextAlignment -> 0], After];NotebookLocate[{RootModificationNBObject, "Coordinates \
Scaling"}];MoveSelection[RootModificationNBObject, All, Cell];NotebookWrite[RootModificationNBObject,Cell[BoxData[
                      RowBox[{ToBoxes[
                            RootMultiplesGridBox[
                              CreateRootMultiplesArray[
                                CoordinatesAsList]]]}]],CellTags -> "Coordinates Scaling",TextAlignment -> -1,CellHorizontalScrolling  ->  True]])

KeepRealPartButton := 
      ButtonBox["Im(z)->0", ButtonEvaluator -> Automatic, 
          Active -> True, 
          ButtonFunction :> (LastRootSelection = 
                CoordinatesAsList; 
              CoordinatesAsList = {CoordinatesAsList[[1]], 0}; 
              RefreshRootModificationNB)] // DisplayForm

\(\(\(
\)\(KeepImaginaryPartButton := 
      ButtonBox["Re(z)->0", ButtonEvaluator -> Automatic, 
          Active -> True, 
          ButtonFunction :> \((LastRootSelection = 
                CoordinatesAsList; 
              CoordinatesAsList = {0, CoordinatesAsList[\([2]\)]}; 
              RefreshRootModificationNB)\)] // DisplayForm\)\)\)

\(\(\(
\)\(ReImPartPrecisionGridBox := 
      GridBox[Prepend[
            Array[{ButtonBox[
                    StyleForm[SuperscriptBox[10, \((#1 - 3)\)], 
                      FontSize -> 13], 
                    ButtonEvaluator -> Automatic, Active -> True, 
                    ButtonFunction :> \((LastRootSelection = 
                          CoordinatesAsList; 
                        CoordinatesAsList = {RoundAtDigit[
                              CoordinatesAsList[\([1]\)], #1 - 3], 
                            CoordinatesAsList[\([2]\)]}; 
                        RefreshRootModificationNB)\)], 
                  ButtonBox[
                    StyleForm[SuperscriptBox[10, \((#1 - 3)\)], 
                      FontSize -> 13], 
                    ButtonEvaluator -> Automatic, Active -> True, 
                    ButtonFunction :> \((LastRootSelection = 
                          CoordinatesAsList; 
CoordinatesAsList = {CoordinatesAsList[\([1]\)], 
                            RoundAtDigit[
                              CoordinatesAsList[\([2]\)], #1 - 3]}; 
                        RefreshRootModificationNB)\)]} &, {3}], {StyleForm["Re(z) Precision", FontSize -> 12], 
              StyleForm["Im(z) Precision", FontSize -> 12]}\ ], 
          ColumnSpacings -> 1, RowSpacings -> 0] // 
        DisplayForm\)\)\)

\(\(\(
\)\(UndoButton := 
      ButtonBox["Undo", ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> \((CoordinatesAsList = 
              LastRootSelection; RefreshRootModificationNB)\)]\)\)\)

CancelButton := 
      ButtonBox["Cancel", ButtonEvaluator -> Automatic, 
          Active -> True, 
          ButtonFunction :> (CoordinatesAsList = 
                InitialRootValue; InitialRootValue =. ; 
              LastRootSelection =. ; NotebookClose[ButtonNotebook[]]; 
              SetOptions[RootsAssignmentNBObject, Visible -> True, 
                WindowFloating -> True, Editable -> False])] // 
        DisplayForm

\(\(\(
\)\(ResetButton := 
      ButtonBox["Reset", ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> \((LastRootSelection = 
              CoordinatesAsList; CoordinatesAsList = InitialRootValue; 
            RefreshRootModificationNB)\)]\)\)\)

\(\(\(
\)\(\(CloseRootModificationNBButton := 
      ButtonBox["Finish", ButtonEvaluator -> Automatic, 
          Active -> True, 
          ButtonFunction :> \((InitialRootValue =. ; 
              LastRootSelection =. ; 
              ComplexRoot = ComplexForm[CoordinatesAsList]; 
              DisplayComplex[CoordinatesAsList]; 
              NotebookClose[ButtonNotebook[]]; 
              SetOptions[RootsAssignmentNBObject, Visible -> True, 
                WindowFloating -> True, Editable -> False])\)] // 
        DisplayForm\)\(
\)\(
\)
    \)\)\)

RootModificationNB:=Notebook[{\(Cell[
                    BoxData[
                      RowBox[{"z=", 
                          ToBoxes[
                            ComplexForm[
                              CoordinatesAsList]], "                  ", 
                          Cell[BoxData[
                              RowBox[{GridBox[{{UndoButton}, {ResetButton}}]}]]]}]], CellTags -> "Current Root Selection", 
                    TextAlignment -> 0]\),Cell[BoxData[
                        RowBox[{ToBoxes[
                              RootMultiplesGridBox[
                                CreateRootMultiplesArray[
                                  CoordinatesAsList]]]}]],CellTags -> "Coordinates Scaling",TextAlignment -> -1,CellHorizontalScrolling  ->  True],Cell[
                    BoxData[RowBox[{ToBoxes[ReImPartPrecisionGridBox]}]], 
                    TextAlignment -> 0],Cell[BoxData[RowBox[{ToBoxes[KeepRealPartButton]}]], 
                    TextAlignment -> 0],Cell[
                    BoxData[
                      RowBox[{ToBoxes[CancelButton], 
                          ToBoxes[CloseRootModificationNBButton]}]], 
                    TextAlignment -> 1, FontSize -> 14]},ShowCellTags -> True,ShowCellBracket -> False,WindowSize -> {FitAll, 400},ScrollingOptions -> {PagewiseScrolling -> 
                    True, PagewiseDisplay -> Inherited, 
                  RealTimeScrolling -> Inherited, 
                  JumpScrolling -> Inherited, 
                  HorizontalScrollRange -> 3500, 
                  SpeedParameters -> Inherited},WindowFloating -> True,Background -> Options[ButtonBox, 
                    Background][[1, 2]],ShowSelection -> False,WindowFrame -> "Palette",WindowElements -> {"HorizontalScrollBar"},WindowFrameElements -> {""},WindowTitle -> "Selection Manipulation"];
  
ObtainNumberB := 
        ButtonBox[RowBox[{"Obtain", " ", "Number"}], 
          ButtonFunction :> 
            CompoundExpression[ObtainComplexFromSelectedCoordinates, 
              DisplayComplex[CoordinatesAsList]], 
          ButtonEvaluator -> Automatic, Active -> True]
  
SelectionModificationButton := 
      ButtonBox["Modify Selection", ButtonEvaluator -> Automatic, 
        Active -> True, 
        ButtonFunction :> (If[VectorQ[CoordinatesAsList], 
              InitialRootValue = CoordinatesAsList; 
              RootModificationNBObject = 
                NotebookPut[RootModificationNB]])]

\( (*This\ is\ the\ definition\ of\ "multiply"\ \(\(button\)\(.\)\)*) \)

\(MultiplyB := 
      ButtonBox["Multiply", 
        ButtonFunction :> 
          CompoundExpression[
            Set[MultiplySelection, 
              Input["Multiply Selection by....(if input has the form {x,y} then the real part and the imaginary will be multiplied by x and y respectively"]], 
            If[LessEqual[Length[MultiplySelection], 2], 
              CompoundExpression[
                TimesBy[CoordinatesAsList, MultiplySelection], 
                Set[ComplexRoot, ComplexForm[CoordinatesAsList]]]], 
            DisplayComplex[CoordinatesAsList]], 
        ButtonEvaluator -> Automatic, 
Active -> True]\)

\( (*This\ is\ the\ definition\ of\ the\ "round coordinates button"\ *) \)

RoundCoordinatesB := 
      ButtonBox[RowBox[{"Round", " ", "Coordinates"}], 
        ButtonFunction :> 
          CompoundExpression[
            Set[DigitPos, 
              Input["Select position of digit to be rounded...(Negatives \
corespond to decimal digits)"]], 
            Set[CoordinatesAsList, 
              RoundAtDigit[CoordinatesAsList, DigitPos]], 
            Set[ComplexRoot, ComplexForm[CoordinatesAsList]], 
            DisplayComplex[CoordinatesAsList]], 
        ButtonEvaluator -> Automatic, Active -> True]

\(\(\(EnterRootKeyboard := 
      ButtonBox["Define Root(keyboard)", 
        ButtonEvaluator -> Automatic, Active -> True, 
        ButtonFunction :> \((ComplexRoot = GetComplexRoot; 
            CoordinatesAsList = {GeneralizedRe[ComplexRoot], 
                GeneralizedIm[ComplexRoot]}; 
            DisplayComplex[CoordinatesAsList])\)]\)\(
\)
    \)\)

ToPolynomialAsRootB := 
      ButtonBox[
        RowBox[{"z", "->", 
            RowBox[{"Polynomial", " ", "Root"}]}], 
        ButtonFunction :> 
          CompoundExpression[
            Set[Dif, 
              Plus[Part[DkPolynomialsDegrees, PolynomialsIndex], 
                Times[-1, Part[NumberOfRoots, PolynomialsIndex]]]], 
            If[And[GreaterEqual[Dif, 2], 
                Unequal[ToString[ComplexExpand[Times[2, ComplexRoot]]], 
                  ToString[
                    ComplexExpand[
                      Plus[ComplexRoot, 
                        GeneralizedConjugate[ComplexRoot]]]]]], 
              CompoundExpression[
                Set[Part[PolynomialsList, PolynomialsIndex], 
                  Rationalize[
                    Times[Part[PolynomialsList, PolynomialsIndex], 
                      Plus[var, Times[-1, ComplexRoot]], 
                      Plus[var, 
                        Times[-1, 
                          ComplexExpand[
                            GeneralizedConjugate[ComplexRoot]]]]]]], 
                AddTo[Part[NumberOfRoots, PolynomialsIndex], 2]]], 
            If[And[GreaterEqual[Dif, 1], 
                Equal[ToString[Times[2, ComplexRoot]], 
                  ToString[
                    ComplexExpand[
                      Plus[ComplexRoot, 
                        GeneralizedConjugate[ComplexRoot]]]]]], 
              CompoundExpression[
                Set[Part[PolynomialsList, PolynomialsIndex], 
                  Rationalize[
                    Times[Part[PolynomialsList, PolynomialsIndex], 
                      Plus[var, Times[-1, ComplexRoot]]]]], 
                AddTo[Part[NumberOfRoots, PolynomialsIndex], 1]]], 
            DisplayPolynomial[Part[PolynomialsList, PolynomialsIndex], var], 
            DisplayRootsRemaining[PolynomialsIndex], 
            If[Equal[Part[NumberOfRoots, PolynomialsIndex], 
                Part[DkPolynomialsDegrees, PolynomialsIndex]], 
              StatusMessage[
                Cell[BoxData[
                    RowBox[{"The polynomial ", 
                        SubscriptBox["d", PolynomialsIndex], 
                        ToBoxes["("], var, 
                        ToBoxes[") has already reached the required degree.\
"]}]], "TraditionalForm", FontWeight -> "Bold", 
                  CellTags -> "Status", ShowCellTags -> True, 
                  ShowCellBracket -> False]], 
              StatusMessage[
                Cell[TextData[{""}], "Input", 
                  CellTags -> "Status", ShowCellTags -> True, 
                  ShowCellBracket -> False]]], 
            If[Equal[NumberOfRoots, DkPolynomialsDegrees], 
              CompoundExpression[Set[AppropriateDenominatorMatrix, True], 
                StatusMessage[
                  Cell[BoxData[
                      RowBox[{"The denominator matrix ", 
                          SubscriptBox["D", "C"], ToBoxes["("], 
                          var, ToBoxes[") is defined. Press the \"Finish\" \
button to exit."]}]], "TraditionalForm", FontWeight -> "Bold", 
                    CellTags -> "Status", ShowCellTags -> True, 
                    ShowCellBracket -> False]]], 
              Set[AppropriateDenominatorMatrix, False]]], 
        ButtonEvaluator -> Automatic, Active -> True]

\(ResetPolynomialB := 
      ButtonBox[
        RowBox[{"Reset", " ", "Current", " ", "Polynomial"}], 
        ButtonFunction :> 
          CompoundExpression[Set[Part[PolynomialsList, PolynomialsIndex], 1], 
            Set[Part[NumberOfRoots, PolynomialsIndex], 0], 
            DisplayPolynomial[Part[PolynomialsList, PolynomialsIndex], var], 
            DisplayRootsRemaining[PolynomialsIndex], 
            StatusMessage[
              Cell[TextData[{""}], "Input", 
                CellTags -> "Status", ShowCellTags -> True, 
                ShowCellBracket -> False]]], 
        ButtonEvaluator -> Automatic, Active -> True]\)

\( (*This\ is\ the\ definition\ of\ the\ "PreviousPolynomial"\ button*) \)

\(PreviousPolyB := 
      ButtonBox[
        RowBox[{RowBox[{"<<", " ", "Previous"}], " ", "Polynomial"}], 
        ButtonFunction :> 
          CompoundExpression[
            If[Greater[PolynomialsIndex, 1], 
              AddTo[PolynomialsIndex, \(-1\)]], 
            If[Unequal[DkPolynomialsDegrees, NumberOfRoots], 
              If[Equal[Part[DkPolynomialsDegrees, PolynomialsIndex], 
                  Part[NumberOfRoots, PolynomialsIndex]], 
                StatusMessage[
                  Cell[TextData[{"The polynomial ", 
                        Cell[BoxData[
                            SubscriptBox["d", PolynomialsIndex]]], 
                        ToBoxes["("], var, 
                        ToBoxes[") has already acquired its required degree."]}], "Input", CellTags -> "Status", 
                    ShowCellTags -> True, 
                    ShowCellBracket -> False]], 
                StatusMessage[
                  Cell[TextData[{""}], "Input", 
                    CellTags -> "Status", ShowCellTags -> True, 
                    ShowCellBracket -> False]]], 
              StatusMessageCell[
                BoxData[
                  RowBox[{"The denominator matrix ", 
                      SubscriptBox["D", "C"], ToBoxes["("], var, 
                      ToBoxes[") is defined. Press the "Finish" button to exit."]}]], "TraditionalForm", FontWeight -> "Bold", 
                CellTags -> "Status", ShowCellTags -> True]], 
            DisplayPolynomial[Part[PolynomialsList, PolynomialsIndex], var], 
            DisplayRootsRemaining[PolynomialsIndex]], 
        ButtonEvaluator -> Automatic, Active -> True]\)

\( (*This\ is\ the\ definition\ of\ the\ "NextPolynomial"\ button*) \)

\(NextPolyB := 
      ButtonBox[
        RowBox[{RowBox[{"Next", " ", "Polynomial"}], "  ", ">>"}], 
        ButtonFunction :> 
          CompoundExpression[
            If[Less[PolynomialsIndex, PolynomialsNumber], 
              AddTo[PolynomialsIndex, 1]], 
            If[Unequal[DkPolynomialsDegrees, NumberOfRoots], 
              If[Equal[Part[DkPolynomialsDegrees, PolynomialsIndex], 
                  Part[NumberOfRoots, PolynomialsIndex]], 
                StatusMessage[
                  Cell[TextData[{"The polynomial ", 
                        Cell[BoxData[
                            SubscriptBox["d", PolynomialsIndex]]], 
                        ToBoxes["("], var, 
                        ToBoxes[") has already acquired its required degree."]}], "Input", CellTags -> "Status", 
                    ShowCellTags -> True, 
                    ShowCellBracket -> False]], 
                StatusMessage[
                  Cell[TextData[{""}], "Input", 
                    CellTags -> "Status", ShowCellTags -> True, 
                    ShowCellBracket -> False]]], 
              StatusMessage[
                Cell[BoxData[
                    RowBox[{"The denominator matrix ", 
                        SubscriptBox["D", "C"], ToBoxes["("], 
                        var, ToBoxes[") is defined. Press the "Finish" button to exit."]}]], "TraditionalForm", FontWeight -> "Bold", 
                  CellTags -> "Status", 
                  ShowCellTags -> True]]], 
            DisplayPolynomial[Part[PolynomialsList, PolynomialsIndex], var], 
            DisplayRootsRemaining[PolynomialsIndex]], 
        ButtonEvaluator -> Automatic, Active -> True]\)

\(CloseComplexWindowsB := 
      ButtonBox[RowBox[{"Finish"}], 
        ButtonFunction :> 
          CompoundExpression[Unset[z], 
            If[Equal[DkPolynomialsDegrees, NumberOfRoots], 
              CompoundExpression[Set[AppropriateDenominatorMatrix, True], 
                Set[DenominatorMatrix, 
                  Collect[
                    Expand[Rationalize[DiagonalMatrix[PolynomialsList]]], 
                    var]], NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix"}], 
                SelectionMove[MainDisplayNBObject, All, Cell], 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[BoxData[
                      RowBox[{SubscriptBox["D", "C"], 
                          ToBoxes["("], var, ToBoxes[")="], 
                          ToBoxes[
                            MatrixForm[
                              DenominatorMatrix]]}]], "TraditionalForm", \ FontSize\  -> \ 16, \ FontFamily\  -> \ "Arial", \ 
                    FontWeight\  -> \ "Bold", 
                    CellTags -> "Closed Loop System Denominator Matrix", CellHorizontalScrolling -> True, ShowCellTags -> False], 
                  After]], Set[AppropriateDenominatorMatrix, False]; 
              NotebookLocate[{MainDisplayNBObject, "Closed Loop System Denominator Matrix"}]; SelectionMove[MainDisplayNBObject, All, Cell]; 
              NotebookWrite[MainDisplayNBObject, 
                Cell[TextData["The Denominator Matrix has not been defined yet.Please define the Denominator Matix."], 
                  CellTags -> "Closed Loop System Denominator Matrix", 
                  ShowCellTags -> False, Selectable -> True], After]], 
            NotebookClose[ComplexPlaneNBObject], 
            NotebookClose[RootsAssignmentNBObject], 
            SetOptions[MainButtonsPaletteObject, Visible -> True, 
              Editable -> False]], ButtonEvaluator -> Automatic, 
        Active -> True]\)

\(\(\(
\)\( (*GENERAL\ NOTEBOOK\ MANIPULATION\ TOOLS*) \)\(
\)\(\(\(NotebookCenter[
        x_NotebookObject] := 
\((
VisibleDef = \(Options[x, 
              Visible]\)[\([1, 2]\)]; 
SetOptions[x, 
          Visible -> 
            False]; 
WindowDimensionsSmallerBy = \(AbsoluteOptions[x, ScreenRectangle]\)[\([1, 2, All, 2]\)] - {0, 
              25} - \(AbsoluteOptions[x, WindowSize]\)[\([1, 2]\)]; 
        Margins := 
          Round[Transpose[{\((WindowDimensionsSmallerBy/
                      2)\) //. \((val_ /; 
                        NumberQ[val] && val < 0)\) :> 
                    0, \((WindowDimensionsSmallerBy/
                      2)\) //. \((val_ /; 
                        NumberQ[val] && val < 0)\) :> 
                    0}]]; 
SetOptions[x, 
          WindowMargins -> Margins, Visible -> VisibleDef, 
          WindowSize -> {Inherited, 
              Automatic}]
)\)\)\(
\)
    \)

    \(ComplexPlaneWidth := \(Options[SelectedNotebook[], 
              ScreenRectangle]\)[\([1, 2, 1, 2]\)] - 
          60;\)


 (*Essential\ Notebooks*) 

    \(MainDisplayNB = 
        Notebook[{Cell[BoxData[RowBox[{"Strictly Proper Plant"}]], 
              FontWeight -> "Bold", FontColor -> RGBColor[0, 0, 1]], 
            Cell["", Selectable -> True, ShowCellTags -> False, 
              CellTags -> "Strictly Proper Plant", 
              CellHorizontalScrolling -> True], 
            Cell[BoxData[
                RowBox[{"Closed Loop System Denominator Matrix Row Powers"}]], FontWeight -> "Bold", FontColor -> RGBColor[0, 0, 1]], 
            Cell["", Selectable -> True, ShowCellTags -> False, 
              CellTags -> "Closed Loop System Denominator Matrix Row Powers", CellHorizontalScrolling -> True], 
            Cell[BoxData[
                RowBox[{"Closed Loop System Denominator Matrix"}]], 
              FontWeight -> "Bold", FontColor -> RGBColor[0, 0, 1]], 
            Cell["", Selectable -> True, ShowCellTags -> False, 
              CellTags -> "Closed Loop System Denominator Matrix"], 
            Cell[
              BoxData[RowBox[{ToBoxes["Class Of "], 
                    SubscriptBox["D", "C"], 
                    ToBoxes[" Assigning Stabilizing Compensators"]}]], 
              FontWeight -> "Bold", FontColor -> RGBColor[0, 0, 1]], 
            Cell["", Selectable -> True, ShowCellTags -> False, 
              CellTags -> "Class Of Compensators"]}, 
          WindowSize -> {2500, 2500}, Selectable -> False, 
          ShowCellBracket -> False, 
          WindowTitle -> "Computation of the class of denominator assigning stabilizing compensators...", 
          ScrollingOptions -> {PagewiseScrolling -> False, 
              PagewiseDisplay -> Inherited, 
              RealTimeScrolling -> Inherited, 
              JumpScrolling -> Inherited, 
              HorizontalScrollRange -> 29500, 
              SpeedParameters -> Inherited}];\)


    \(MainButtonsPalette := 
        Notebook[{Cell[
              BoxData[GridBox[{{"Strictly Proper Plant"}, {DefinePlantT}, {DefinePlantB}, {"Closed Loop System"}, {"Denominator Matrix"}, {DefineKsiRowDegreesButton}, {DisplayGWResultant}, {DefineDenominatorMatrix}, {"Class Of Denominator Assigning"}, {" Stabilizing Compensators"}, {ComputeCompensators}, {ParametersValuesButton}, {"Time Response"}, {ResponsePlotsButton}, {"Program"}, {ExitApp}, {HelpNBButton}}, 
                  RowSpacings -> {1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 
                      0}]]]}, WindowFrame -> Palette, 
          WindowSize -> FitAll, WindowElements -> {}, 
          ShowCellBracket -> False, 
          Background -> \(Options[ButtonBox, Background]\)[\([1, 2]\)], 
          CellMargins -> {{0, 0}, {0, 0}}, 
          WindowFrameElements -> {}, CellFrame -> 1, 
          CellFrameMargins -> {{0, 0}, {0, 4}}, Editable -> False, 
          WindowTitle -> "Basic Buttons", WindowFloating -> True, 
          WindowMargins -> {{Automatic, 0}, {Automatic, 0}}, 
          ScrollingOptions -> {PagewiseScrolling -> True, 
              PagewiseDisplay -> Inherited, 
              RealTimeScrolling -> Inherited, 
              JumpScrolling -> Inherited, 
              HorizontalScrollRange -> Inherited, 
              SpeedParameters -> Inherited}];\)


    \(RootsAssignmentNB := 
        Notebook[{Cell[
              BoxData[GridBox[{{"Root Definition"}, {ObtainNumberB}, {SelectionModificationButton}, {EnterRootKeyboard}, {"Root Assignment"}, {ToPolynomialAsRootB}, {ResetPolynomialB}, {"Polynomial Navigator"}, {PreviousPolyB}, {NextPolyB}, {"Close this window"}, {CloseComplexWindowsB}}, 
                  RowSpacings -> {1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 
                      0}]]]}, WindowFrame -> Palette, 
          WindowSize -> FitAll, WindowElements -> {}, 
          WindowFrameElements -> {"CloseBox"}, 
          ShowCellBracket -> False, 
          Background -> \(Options[ButtonBox, Background]\)[\([1, 2]\)], 
          CellMargins -> {{0, 0}, {0, 0}}, CellFrame -> 1, 
          CellFrameMargins -> {{0, 0}, {0, 4}}, Editable -> False, 
          WindowTitle -> "Denominator Matrix Elements Definition", 
          WindowFloating -> True, 
          WindowMargins -> {{Automatic, 0}, {Automatic, 
                0}}];\)


    \(ComplexPlaneNB = 
        Notebook[{Cell[
              GraphicsData["PostScript", \*""\<\
%!
%%Creator: Mathematica
%%AspectRatio: .415
MathPictureStart
/Mabs {
Mgmatrix idtransform
Mtmatrix dtransform
} bind def
/Mabsadd { Mabs
3 -1 roll add
3 1 roll add
exch } bind def
%% Graphics
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10  scalefont  setfont
% Scaling calculations
0.97619 0.952381 0.0147151 0.588604 [
[.02381 .00222 -6 -9 ]
[.02381 .00222 6 0 ]
[.11905 .00222 -12 -9 ]
[.11905 .00222 12 0 ]
[.21429 .00222 -12 -9 ]
[.21429 .00222 12 0 ]
[.30952 .00222 -12 -9 ]
[.30952 .00222 12 0 ]
[.40476 .00222 -12 -9 ]
[.40476 .00222 12 0 ]
[.5 .00222 -12 -9 ]
[.5 .00222 12 0 ]
[.59524 .00222 -12 -9 ]
[.59524 .00222 12 0 ]
[.69048 .00222 -12 -9 ]
[.69048 .00222 12 0 ]
[.78571 .00222 -12 -9 ]
[.78571 .00222 12 0 ]
[.88095 .00222 -12 -9 ]
[.88095 .00222 12 0 ]
[.96369 .07358 -30.625 -6.28125 ]
[.96369 .07358 0 6.28125 ]
[.96369 .13244 -30.625 -6.28125 ]
[.96369 .13244 0 6.28125 ]
[.96369 .1913 -30.625 -6.28125 ]
[.96369 .1913 0 6.28125 ]
[.96369 .25016 -30.625 -6.28125 ]
[.96369 .25016 0 6.28125 ]
[.96369 .30902 -30.625 -6.28125 ]
[.96369 .30902 0 6.28125 ]
[.96369 .36788 -30.625 -6.28125 ]
[.96369 .36788 0 6.28125 ]
[.96369 .42674 -30.625 -6.28125 ]
[.96369 .42674 0 6.28125 ]
[.96369 .4856 -30.625 -6.28125 ]
[.96369 .4856 0 6.28125 ]
[.96369 .54446 -30.625 -6.28125 ]
[.96369 .54446 0 6.28125 ]
[.96369 .60332 -10 -6.28125 ]
[.96369 .60332 0 6.28125 ]
[.5 .63053 -241.25 0 ]
[.5 .63053 241.25 15.1875 ]
[ 0 0 0 0 ]
[ 1 .61803 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
.8 g
.25 Mabswid
[ ] 0 setdash
.88095 0 m
.88095 .61803 L
s
.78571 0 m
.78571 .61803 L
s
.69048 0 m
.69048 .61803 L
s
.59524 0 m
.59524 .61803 L
s
.5 0 m
.5 .61803 L
s
.40476 0 m
.40476 .61803 L
s
.30952 0 m
.30952 .61803 L
s
.21429 0 m
.21429 .61803 L
s
.11905 0 m
.11905 .61803 L
s
.02381 0 m
.02381 .61803 L
s
0 .07358 m
1 .07358 L
s
0 .13244 m
1 .13244 L
s
0 .1913 m
1 .1913 L
s
0 .25016 m
1 .25016 L
s
0 .30902 m
1 .30902 L
s
0 .36788 m
1 .36788 L
s
0 .42674 m
1 .42674 L
s
0 .4856 m
1 .4856 L
s
0 .54446 m
1 .54446 L
s
0 .60332 m
1 .60332 L
s
0 g
.02381 .01472 m
.02381 .02097 L
s
[(-1)] .02381 .00222 0 1 Mshowa
.11905 .01472 m
.11905 .02097 L
s
[(-0.9)] .11905 .00222 0 1 Mshowa
.21429 .01472 m
.21429 .02097 L
s
[(-0.8)] .21429 .00222 0 1 Mshowa
.30952 .01472 m
.30952 .02097 L
s
[(-0.7)] .30952 .00222 0 1 Mshowa
.40476 .01472 m
.40476 .02097 L
s
[(-0.6)] .40476 .00222 0 1 Mshowa
.5 .01472 m
.5 .02097 L
s
[(-0.5)] .5 .00222 0 1 Mshowa
.59524 .01472 m
.59524 .02097 L
s
[(-0.4)] .59524 .00222 0 1 Mshowa
.69048 .01472 m
.69048 .02097 L
s
[(-0.3)] .69048 .00222 0 1 Mshowa
.78571 .01472 m
.78571 .02097 L
s
[(-0.2)] .78571 .00222 0 1 Mshowa
.88095 .01472 m
.88095 .02097 L
s
[(-0.1)] .88095 .00222 0 1 Mshowa
0 .01472 m
1 .01472 L
s
.97619 .07358 m
.98244 .07358 L
s
gsave
.96369 .07358 -91.625 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0.1) show
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
89.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 .13244 m
.98244 .13244 L
s
gsave
.96369 .13244 -91.625 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0.2) show
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
89.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 .1913 m
.98244 .1913 L
s
gsave
.96369 .1913 -91.625 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0.3) show
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
89.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 .25016 m
.98244 .25016 L
s
gsave
.96369 .25016 -91.625 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0.4) show
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
89.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 .30902 m
.98244 .30902 L
s
gsave
.96369 .30902 -91.625 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0.5) show
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
89.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 .36788 m
.98244 .36788 L
s
gsave
.96369 .36788 -91.625 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0.6) show
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
89.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 .42674 m
.98244 .42674 L
s
gsave
.96369 .42674 -91.625 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0.7) show
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
89.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 .4856 m
.98244 .4856 L
s
gsave
.96369 .4856 -91.625 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0.8) show
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
89.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 .54446 m
.98244 .54446 L
s
gsave
.96369 .54446 -91.625 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0.9) show
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
83.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
89.625 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 .60332 m
.98244 .60332 L
s
gsave
.96369 .60332 -71 -10.2813 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 20.5625 translate 1 -1 scale
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 16.563 moveto
 100000.000 16.563 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 16.563 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
63.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(i) show
69.000 12.813 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
.97619 0 m
.97619 .61803 L
s
gsave
.5 .63053 -302.25 -4 Mabsadd m
1 1 Mabs scale
currentpoint translate
0 23.1875 translate 1 -1 scale
/MISOfy
{
    /newfontname exch def
    /oldfontname exch def

    oldfontname findfont
    dup length dict begin
        {1 index /FID ne {def} {pop pop} ifelse} forall
        /Encoding WindowsANSIEncoding def
        currentdict
    end

    newfontname exch definefont pop
} def
0.996 0.996 0.996 setrgbcolor
newpath
 61.000 19.188 moveto
 100000.000 19.188 lineto
 100000.000 4.000 lineto
 61.000 4.000 lineto
 61.000 19.188 lineto
closepath
fill
0.000 0.000 0.000 setrgbcolor
63.000 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
63.000 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(Quartile) show
149.063 15.188 moveto
(of) show
177.750 15.188 moveto
(the) show
216.000 15.188 moveto
(Complex) show
292.500 15.188 moveto
(Plane) show
340.313 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(:) show
%%IncludeResource: font Math2Mono-Bold
%%IncludeFont: Math2Mono-Bold
/Math2Mono-Bold findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
359.438 15.188 moveto
(8) show
369.000 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(z) show
%%IncludeResource: font Math1Mono-Bold
%%IncludeFont: Math1Mono-Bold
/Math1Mono-Bold findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(e) show
%%IncludeResource: font Math5Mono-Bold
%%IncludeFont: Math5Mono-Bold
/Math5Mono-Bold findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(\\302) show
%%IncludeResource: font Math2Mono-Bold
%%IncludeFont: Math2Mono-Bold
/Math2Mono-Bold findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
407.625 15.188 moveto
(\\220) show
426.750 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(Rez) show
455.438 15.188 moveto
%%IncludeResource: font Math1Mono-Bold
%%IncludeFont: Math1Mono-Bold
/Math1Mono-Bold findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(<) show
465.000 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0) show
474.563 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(,) show
484.125 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(Imz) show
512.813 15.188 moveto
%%IncludeResource: font Math1Mono-Bold
%%IncludeFont: Math1Mono-Bold
/Math1Mono-Bold findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(\\263) show
522.375 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
(0) show
%%IncludeResource: font Math2Mono-Bold
%%IncludeFont: Math2Mono-Bold
/Math2Mono-Bold findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
531.938 15.188 moveto
(<) show
541.500 15.188 moveto
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 16.000 scalefont
[1 0 0 -1 0 0 ] makefont setfont
0.000 0.000 0.000 setrgbcolor
0.000 0.000 rmoveto
1.000 setlinewidth
grestore
0 0 m
1 0 L
1 .61803 L
0 .61803 L
closepath
clip
newpath
.008 w
.97619 .60332 Mdot
.02381 .01472 Mdot
% End of Graphics
MathPictureEnd
\
\>""], \ "Graphics", CellFrame -> True, 
              CellTags -> "CPlot", ShowCellTags -> False, 
              ShowCellBracket -> False, 
              DefaultNaturalLanguage -> Language, 
              AspectRatioFixed -> False, 
              ImageSize -> {ComplexPlaneWidth, Automatic}, 
              ImageMargins -> {{5, 0}, {0, 0}}, 
              ImageRegion -> {{0, 1}, {0, 1}}, 
              FontFamily -> "Courier New CE"], 
            Cell[BoxData[""], "Input", Selectable -> False, 
              ShowCellBracket -> False, 
              CellMargins -> {{Inherited, Inherited}, {2.`, 2.`}}, 
              CellTags -> "Complex"], 
            Cell["", "Input", Selectable -> False, 
              CellFrame -> False, ShowCellBracket -> False, 
              CellMargins -> {{Inherited, Inherited}, {2.`, 2.`}}, 
              ShowCellTags -> True, CellTags -> "Status"], 
            Cell["", "Input", Selectable -> False, 
              CellFrame -> False, ShowCellBracket -> False, 
              CellMargins -> {{Inherited, Inherited}, {2.`, 2.`}}, 
              ShowCellTags -> True, 
              CellTags -> "Roots Remaining"], 
            Cell["", "Input", Selectable -> False, 
              ShowCellBracket -> False, 
              CellMargins -> {{Inherited, Inherited}, {2.`, 2.`}}, 
              ShowCellTags -> True, CellTags -> "Polynomial"]}, 
          ShowCellTags -> True, WindowSize -> {2500, 2500}, 
          WindowTitle -> "Denominator Matrix Definition...Please define the elements-polynomials by selecting their roots", 
          ShowSelection -> False, 
          ScrollingOptions -> {PagewiseScrolling -> False, 
              PagewiseDisplay -> Inherited, 
              RealTimeScrolling -> Inherited, 
              JumpScrolling -> Inherited, 
              HorizontalScrollRange -> Inherited, 
              SpeedParameters -> Inherited}, 
          WindowFrameElements -> {"ZoomBox", "ResizeArea"}];\)\)\)\)

ResponsePlotsNB := 
      Notebook[{Cell["Feedback System Time Response"], 
          Cell["", CellTags -> "Response Plot", 
            ShowCellTags -> True]}]

\(MyDisplayFunction[
        gr : \((_Graphics | _Graphics3D | _SurfaceGraphics | _DensityGraphics | _ContourGraphics)\)] := 
      Module[{psstring, cellexpr}, 
        NotebookLocate[{ResponsePlotsNBObject, "Response Plot"}]; 
        SelectionMove[ResponsePlotsNBObject, All, Cell]; 
        psstring = DisplayString[gr]; 
        cellexpr = 
          Cell[TextData[{Cell[
                  GraphicsData["PostScript", 
                    psstring]]}], "Graphics", 
            TextAlignment -> Center, CellTags -> "Response Plot", 
            ShowCellTags -> True]; 
        NotebookWrite[ResponsePlotsNBObject, cellexpr]]\)

DisplayResponse[OutputIndex_, RespVec_, tmaximum_] := 
      Plot[Evaluate[ComplexExpand[RespVec[[OutputIndex, 1]]]], {t, 0, 
          tmaximum}, DisplayFunction -> MyDisplayFunction, 
        PlotLabel -> 
          StyleForm[
            StringForm["`1` System Output Response when `2` Input is the \
`3` function", Subscript["Y", OutputSelection], 
              Subscript["U", InputSelection], 
              InputType]
, FontSize -> 20], 
        PlotRange -> All, ImageSize -> 600]

FSTransferFunction[Plant_, XL_, YL_] := 
      Inverse[IdentityMatrix[Dimensions[Plant][[1]]] + 
            Plant . Inverse[XL] . YL] . Plant . Inverse[XL] . YL

ResponseVector[H_, InputVec_, var1_, var2_] := 
      Simplify[ComplexExpand[
          InverseLaplaceTransform[H . InputVec, var1, var2]]]

IncreaseIncrementButton:=ButtonBox["×10",Active -> True,ButtonEvaluator -> Local,ButtonFrame -> "DialogBox",ButtonFunction :> (ParIncrement = 
                ParIncrement*10; RefreshParametersIncrement)]

DecreaseIncrementButton:=ButtonBox[SuperscriptBox["×10", "-1"],Active -> True,ButtonEvaluator -> Local,ButtonFrame -> "DialogBox",ButtonFunction :> (ParIncrement = 
                ParIncrement/10; RefreshParametersIncrement)]

EnterIncrementButton := 
      ButtonBox[ToBoxes[ParIncrement], Active -> True, 
        ButtonFrame -> "Palette", 
        ButtonEvaluator -> Local]

RefreshParametersIncrement := (NotebookLocate["Increment"]; 
        NotebookWrite[SelectedNotebook[], 
          Cell[BoxData[
              GridBox[{{"Increment: i = ", EnterIncrementButton, 
                    IncreaseIncrementButton, DecreaseIncrementButton}}, 
                ColumnSpacings -> 0.1]], CellTags -> "Increment"]]; 
        SetOptions[SelectedNotebook[], 
          WindowSize -> FitAll])

ParameterIncreaseButton[i_Integer] := 
      ButtonBox["+", Active -> True, ButtonFrame -> "DialogBox", 
        ButtonEvaluator -> Local, 
        ButtonFunction :> (tparval[[i]] = 
              tparval[[i]] + ParIncrement; RefreshParameterValue; 
            ParameterChangeAction )]

ParameterDecreaseButton[i_Integer] := 
      ButtonBox["-", Active -> True, ButtonEvaluator -> Local, 
        ButtonFrame -> "DialogBox", 
        ButtonFunction :> (tparval[[i]] = 
              tparval[[i]] - ParIncrement; RefreshParameterValue;  
            ParameterChangeAction )]

EnterParameterValue[i_Integer] := 
      ButtonBox[ToBoxes[N[tparval[[i]], Infinity]], 
        ButtonEvaluator -> Local, Active -> True, 
        ButtonFrame -> "Palette"]

ParameterChangeAction := 
      Module[{TM}, (TM = 
            ClosedLoopSystemTransferFunction //. 
              Table[t[i] -> tparval[[i]], {i, 1, numofparameters}]; 
          ResVec = ResponseVector[TM, InputVector, s, t]; 
          DisplayResponse[OutputSelection, ResVec, Maxt])]

RefreshParameterValue := (NotebookLocate["Parameters"]; 
        NotebookWrite[SelectedNotebook[], 
          Cell[BoxData[
              GridBox[Table[{SubscriptBox["t", j], "=", 
                    EnterParameterValue[j], ParameterIncreaseButton[j], 
                    ParameterDecreaseButton[j]}, {j, numofparameters}], 
                ColumnSpacings -> 0.1]], CellTags -> "Parameters"]]; 
        SetOptions[SelectedNotebook[], 
          WindowSize -> FitAll])

CloseParametersGraphControlNotebook := 
      ButtonBox["Close", Active -> True, 
        ButtonEvaluator -> Local, ButtonFrame -> "DialogBox", 
        ButtonFunction :> 
          NotebookClose[ParametersGraphControlNotebookObject]]

ParametersGraphControlNB[i_Integer] := 
      Notebook[{Cell[
            BoxData[GridBox[{{"Increment: i = ", EnterIncrementButton, 
                    IncreaseIncrementButton, DecreaseIncrementButton}}, 
                ColumnSpacings -> 0.1]], CellTags -> "Increment"], 
          Cell[BoxData[
              GridBox[Table[{SubscriptBox["t", j], "=", 
                    EnterParameterValue[j], ParameterIncreaseButton[j], 
                    ParameterDecreaseButton[j]}, {j, i}], 
                ColumnSpacings -> 0.1]], CellTags -> "Parameters"], 
          Cell[BoxData[CloseParametersGraphControlNotebook]]}, 
        ShowCellTags -> True, WindowFrame -> "Palette", 
        WindowSize -> FitAll, ShowCellBracket -> False, 
        WindowMargins -> {{Automatic, 0}, {Automatic, 0}}, 
        TextAlignment -> Center, WindowElements -> {}]

OutputSelectorUpButton := 
      ButtonBox["↑", Active -> True, 
        ButtonFrame -> "DialogBox", ButtonEvaluator -> Local, 
        ButtonFunction :> 
          If[OutputSelection < NumOut, (OutputSelection++; 
              NotebookLocate[{SelectedNotebook[], "Output"}]; 
              NotebookWrite[SelectedNotebook[], 
                Cell[BoxData[
                    RowBox[{"Display Output Signal: ", 
                        OutputSelection, "   ", OutputSelectorUpButton, 
                        OutputSelectorDownButton}]], 
                  CellTags -> "Output", ShowCellTags -> True, 
                  ShowCellBracket -> False], All]; 
              DisplayResponse[OutputSelection, ResVec, Maxt])]]

OutputSelectorDownButton := 
      ButtonBox["↓", Active -> True, 
        ButtonFrame -> "DialogBox", ButtonEvaluator -> Local, 
        ButtonFunction :> 
          If[OutputSelection > 1, (OutputSelection--; 
              NotebookLocate[{SelectedNotebook[], "Output"}]; 
              NotebookWrite[SelectedNotebook[], 
                Cell[BoxData[
                    RowBox[{"Display Output Signal: ", 
                        OutputSelection, "   ", OutputSelectorUpButton, 
                        OutputSelectorDownButton}]], 
                  CellTags -> "Output", ShowCellTags -> True, 
                  ShowCellBracket -> False], All]; 
              DisplayResponse[OutputSelection, ResVec, Maxt])]]

TypeOfInputButton[type_String] := 
      ButtonBox[type, Active -> True, ButtonEvaluator -> Local, 
        ButtonFrame -> "DialogBox", 
        ButtonFunction :>  (If[type == "Step", 
              InputType = "Impulse"; InputVector = ZeroVector[NumIn]; 
              InputVector[[InputSelection]] = 1; 
              InputVector = Partition[InputVector, 1], 
              InputType = "Step"; InputVector = ZeroVector[NumIn]; 
              InputVector[[InputSelection]] = 1/s; 
              InputVector = Partition[InputVector, 1]]; 
            NotebookLocate[{SelectedNotebook[], "Type Of Input"}]; 
            NotebookWrite[SelectedNotebook[], 
              Cell[BoxData[
                  RowBox[{"Type Of Input Function: ", 
                      TypeOfInputButton[InputType]}]], 
                CellTags -> "Type Of Input", ShowCellTags -> True, 
                ShowCellBracket -> False], All]; 
            Module[{TM}, (TM = 
                  ClosedLoopSystemTransferFunction //. 
                    Table[t[i] -> tparval[[i]], {i, 1, 
                        numofparameters}]; 
                ResVec = ResponseVector[TM, InputVector, s, t]; 
                DisplayResponse[OutputSelection, ResVec, 
                  Maxt])])]

InputSelectorUpButton := 
      ButtonBox["↑", Active -> True, 
        ButtonFrame -> "DialogBox", ButtonEvaluator -> Local, 
        ButtonFunction :> 
          If[InputSelection < NumIn, (InputSelection++; 
              NotebookLocate[{SelectedNotebook[], "Input"}]; 
              NotebookWrite[SelectedNotebook[], 
                Cell[BoxData[
                    RowBox[{"Apply Input Signal: ", 
                        InputSelection, "   ", InputSelectorUpButton, 
                        InputSelectorDownButton}]], CellTags -> "Input", 
                  ShowCellTags -> True, ShowCellBracket -> False], 
                All]; If[InputType == "Impulse", 
                InputVector = ZeroVector[NumIn]; 
                InputVector[[InputSelection]] = 1; 
                InputVector = Partition[InputVector, 1], 
                InputVector = ZeroVector[NumIn]; 
                InputVector[[InputSelection]] = 1/s; 
                InputVector = Partition[InputVector, 1]]; 
              Module[{TM}, (TM = 
                    ClosedLoopSystemTransferFunction //. 
                      Table[t[i] -> tparval[[i]], {i, 1, 
                          numofparameters}]; 
                  ResVec = ResponseVector[TM, InputVector, s, t]; 
                  DisplayResponse[OutputSelection, ResVec, 
                    Maxt])])]]

InputSelectorDownButton := 
      ButtonBox["↓", Active -> True, 
        ButtonFrame -> "DialogBox", ButtonEvaluator -> Local, 
        ButtonFunction :> 
          If[InputSelection > 1, (InputSelection--; 
              NotebookLocate[{SelectedNotebook[], "Input"}]; 
              NotebookWrite[SelectedNotebook[], 
                Cell[BoxData[
                    RowBox[{"Apply Input Signal: ", 
                        InputSelection, "   ", InputSelectorUpButton, 
                        InputSelectorDownButton}]], CellTags -> "Input", 
                  ShowCellTags -> True, ShowCellBracket -> False], 
                All]; If[InputType == "Impulse", 
                InputVector = ZeroVector[NumIn]; 
                InputVector[[InputSelection]] = 1; 
                InputVector = Partition[InputVector, 1], 
                InputVector = ZeroVector[NumIn]; 
                InputVector[[InputSelection]] = 1/s; 
                InputVector = Partition[InputVector, 1]]; 
              Module[{TM}, (TM = 
                    ClosedLoopSystemTransferFunction //. 
                      Table[t[i] -> tparval[[i]], {i, 1, 
                          numofparameters}]; 
                  ResVec = ResponseVector[TM, InputVector, s, t]; 
                  DisplayResponse[OutputSelection, ResVec, 
                    Maxt])])]]

MaxTimeButton:=ButtonBox[Maxt, 
        ButtonFrame -> "DialogBox", ButtonEvaluator -> Local, 
        Active -> True, 
        ButtonFunction :> (Maxt = GetMaxt; 
            NotebookLocate[{SelectedNotebook[], "Time t Range"}]; 
            NotebookWrite[SelectedNotebook[], 
              Cell[BoxData[
                  RowBox[{"Plot Response up to t=", MaxTimeButton}]], 
                CellTags -> "Time t Range", ShowCellTags -> True, 
                ShowCellBracket -> False], All]; 
            DisplayResponse[OutputSelection, ResVec, 
              Maxt])]

GetMaxt := 
      Module[{tMax}, (tMax = Input["Set the maximum value for t:"]; 
          If[NumericQ[tMax] && Positive[tMax], tMax, GetMaxt])]

InputOutputNB := 
      Notebook[{Cell[
            BoxData[RowBox[{"Apply Input Signal: ", 
                  InputSelection, "   ", InputSelectorUpButton, 
                  InputSelectorDownButton}]], CellTags -> "Input", 
            ShowCellTags -> True, ShowCellBracket -> False], 
          Cell[BoxData[
              RowBox[{"Type Of Input Function: ", 
                  TypeOfInputButton[InputType]}]], 
            CellTags -> "Type Of Input", ShowCellTags -> True, 
            ShowCellBracket -> False], 
          Cell[BoxData[
              RowBox[{"Display Output Signal: ", 
                  OutputSelection, "   ", OutputSelectorUpButton, 
                  OutputSelectorDownButton}]], CellTags -> "Output", 
            ShowCellTags -> True, ShowCellBracket -> False], 
          Cell[BoxData[
              RowBox[{"Plot Response up to t=", MaxTimeButton}]], 
            CellTags -> "Time t Range", ShowCellTags -> True, 
            ShowCellBracket -> False]}, WindowFrame -> "Palette", 
        WindowSize -> FitAll, WindowTitle -> "Input/Output Control", 
        WindowMargins -> {{Automatic, 0}, {0, Automatic}}, 
        TextAlignment -> Center, WindowElements -> {}]

ResponsePlotsButton := 
      ButtonBox["Feedback System Response Plots", Active -> True, 
        ButtonEvaluator -> Automatic, 
        ButtonFunction :> (If[ComputedCompensator, 
              SetOptions[MainButtonsPaletteObject, Editable -> True, 
                Visible -> 
                  False]; ({NumOut, 
                    NumIn} = {Dimensions[
                        StrictlyProperPlant][[1]], Dimensions[
                        StrictlyProperPlant][[1]]}; Maxt = 10; 
                tparval = ZeroVector[numofparameters]; ParIncrement = 1; 
                InputSelection = 1; OutputSelection = 1; 
                InputType = "Impulse"; InputVector = ZeroVector[NumIn]; 
                InputVector[[InputSelection]] = 1; 
                InputVector = Partition[InputVector, 1]; 
                ClosedLoopSystemTransferFunction = 
                  FSTransferFunction[StrictlyProperPlant, XL, YL]; 
                ResVec = 
                  ResponseVector[
                    ClosedLoopSystemTransferFunction //. 
                      Table[t[i] -> tparval[[i]], {i, 1, 
                          numofparameters}], InputVector, s, t]; 
                ResponsePlotsNBObject = NotebookPut[ResponsePlotsNB]; 
                ParametersGraphControlNBObject = 
                  NotebookPut[ParametersGraphControlNB[numofparameters]]; 
                InputOutputNBObject = NotebookPut[InputOutputNB]; 
                DisplayResponse[OutputSelection, ResVec, 
                  10]), (SelectionMove[MainDisplayNBObject, All, Cell]; 
                NotebookWrite[MainDisplayNBObject, 
                  Cell[TextData["Cannot compute the closed loop system \
transfer function. Compute class of Compensators first."], 
                    CellTags -> "Class Of Compensators", 
                    ShowCellTags -> False, Selectable -> True], 
                  After])])]

\(\(\( (*Initialization\ and\ display\ of\ MainDisplayNotebook*) \)\(
\)\(MainDisplayNBObject = NotebookPut[MainDisplayNB]; 
    NotebookCenter[MainDisplayNBObject]; 
    MainButtonsPaletteObject = NotebookPut[MainButtonsPalette]; 
    ComputedCompensator = False;



    On\ [General::"spell1"]

    On\ [General::"spell"]\)\)\)

EndPackage[]