## Modelica_LinearSystems2.Math.Complex.Internal

### Package Content

Name | Description
--- | ---
eigenValues_dhseqr | compute eingenvalues of a upper Hessenberg matrix using lapack routine DHSEQR
C_transpose | Computes the transposed matrix of a complex matrix
frobeniusNorm | Return the Frobenius norm of a matrix

## Modelica_LinearSystems2.Math.Complex.Internal.eigenValues_dhseqr

compute eingenvalues of a upper Hessenberg matrix using lapack routine DHSEQR

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Real | H[:, size(H, 1)] |  | Real upper Hessenberg matrix

### Outputs

Type | Name | Description
--- | --- | ---
Complex | zeros[size(H, 1)] | Finite, invariant zeros of ss; size(Zeros,1) <= size(ss.A,1)

### Modelica definition

    function eigenValues_dhseqr
      "compute eingenvalues of a upper Hessenberg matrix using lapack routine DHSEQR"

         import Modelica;
         import Modelica_LinearSystems2.Math.Complex;
         import Modelica_LinearSystems2.Math.Matrices.Internal.eigenvaluesHessenberg;

     input Real H[:,size(H, 1)] "Real upper Hessenberg matrix";
     output Complex zeros[size(H, 1)]
        "Finite, invariant zeros of ss; size(Zeros,1) <= size(ss.A,1)";

    protected
     Integer nx=size(H, 1) "Number of states";
     Real alphaReal[nx];
     Real alphaImag[nx];
     Integer info;

    algorithm
     (alphaReal,alphaImag,info) := eigenvaluesHessenberg(H);
     assert(info == 0,
       "Failed to compute eigenvalues with function Internal.eigenValues_dhseqr(..)");

     for i in 1:nx loop
       zeros[i].re := alphaReal[i];
       zeros[i].im := alphaImag[i];
     end for;

    end eigenValues_dhseqr;

## Modelica_LinearSystems2.Math.Complex.Internal.C_transpose

Computes the transposed matrix of a complex matrix

### Information

Extends from Modelica.Icons.Function (Icon for a function).

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Complex | C[:, :] |  |

### Outputs

Type | Name | Description
--- | --- | ---
Complex | CT[size(C, 2), size(C, 1)] |

### Modelica definition

    function C_transpose
      "Computes the transposed matrix of a complex matrix"
      extends Modelica.Icons.Function;

        import Modelica_LinearSystems2.Math.Complex;
        import Re = Modelica_LinearSystems2.Math.Complex.real;
        import Im = Modelica_LinearSystems2.Math.Complex.imag;

      input Complex C[:,:];
      output Complex CT[size(C, 2),size(C, 1)];
    protected
      Complex j=Complex.j();
      Integer l1;
      Integer l2;
    algorithm
    //  CT := Complex(1)*transpose(C[:,:].re)-j*transpose(C[:,:].im);// too slow
      for l1 in 1:size(C, 1) loop
        for l2 in 1:size(C, 2) loop
    //      CT[l2, l1] := Re(C[l1, l2]) - j*Im(C[l1, l2]);
          CT[l2, l1] := Complex.conj(C[l1,l2]);
        end for;
      end for;

    end C_transpose;

## Modelica_LinearSystems2.Math.Complex.Internal.frobeniusNorm

Return the Frobenius norm of a matrix

### Information

Extends from Modelica.Icons.Function (Icon for a function).

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Complex | A[:, :] |  | Input matrix

### Outputs

Type | Name | Description
--- | --- | ---
Real | result | frobenius norm of matrix A

### Modelica definition

    function frobeniusNorm "Return the Frobenius norm of a matrix"
      extends Modelica.Icons.Function;
          import Modelica_LinearSystems2.Math.Complex;
      input Complex A[:,:] "Input matrix";
      output Real result=0.0 "frobenius norm of matrix A";
    algorithm
      for i1 in 1:size(A, 1) loop
        for i2 in 1:size(A, 2) loop
          result := result + Complex.real(A[i1, i2]*Complex.conj(A[i1, i2]));
        end for;
      end for;
      result := sqrt(result);
    end frobeniusNorm;