# Building a symmetric matrix w/given eigenvectors and eigenvalues

octave> x1 = [3 7] # choose x1
x1 =

  3  7

octave> x2 = [-7 3] # x2 is orthogonal to x1
x2 =

  -7   3

octave> x1 = x1/sqrt(x1 * x1') # make x1 have unit length
x1 =

  0.39392  0.91915

octave> x2 = x2/sqrt(x2 * x2') # make x2 have unit length
x2 =

  -0.91915   0.39392

octave> A1 = 2 * (x1' * x1) # A1 is symmetric and rank(A1) = 1
A1 =

  0.31034  0.72414
  0.72414  1.68966

octave> A2 = 5 * (x2' * x2) # A2 is symmetric and rank(A2) = 1
A2 =

   4.22414  -1.81034
  -1.81034   0.77586

octave> (A1 * x1')/2 - x1' # x1 is a right eigenvector of A1 w/eigenvalue 2
ans =

  0
  0

octave> (A2 * x2')/5 - x2' # x2 is a right eigenvector of A2 w/eigenvalue 5
ans =

    1.1102e-16
   -5.5511e-17

octave> (x1 * A1)/2 - x1 # x1 is a left eigenvector of A1 w/eigenvalue 2
ans =

  0  0

octave> (x2 * A2)/5 - x2 # x2 is a left eigenvector of A2 w/eigenvalue 5
ans =

    1.1102e-16   -5.5511e-17

octave> A = A1 + A2 # A is symmetric and rank(A) = 2
A =

   4.5345  -1.0862
  -1.0862   2.4655

octave> (A * x1')/2 - x1' # x1 is a right eigenvector of A w/eigenvalue 2
ans =

   1.1102e-16
   1.1102e-16

octave> (A * x2')/5 - x2' # x2 is a right eigenvector of A w/eigenvalue 5
ans =

    1.1102e-16
   -5.5511e-17

octave> (x1 * A)/2 - x1 # x1 is a left eigenvector of A w/eigenvalue 2
ans =

   1.1102e-16   1.1102e-16

octave> (x2 * A)/5 - x2 # x2 is a left eigenvector of A w/eigenvalue 5
ans =

    1.1102e-16   -5.5511e-17

octave> x1 * x1' # x1 and x2 are orthonormal
ans = 1

octave> x2 * x2'
ans = 1

octave> x1 * x2'
ans =  -2.8704e-17

# Building a non-symmetric matrix w/given eigenvectors and eigenvalues

octave> x1 = [5 2] # choose x1
x1 =

  5  2

octave> y2 = [-2 5] # y2 is orthogonal to x1
y2 =

  -2   5

octave> y1 = [1 4] # choose y1
y1 =

  1  4

octave> x2 = [-4 1] # x2 is orthogonal to y1
x2 =

  -4   1

octave> a1=sqrt(x1 * y1') # make x1 * y1' equal to one
a1 = 3.6056

octave> x1=x1/a1
x1 =

  1.38675  0.55470

octave> y1=y1/a1
y1 =

  0.27735  1.10940

octave> a2 = sqrt(x2 * y2') # make x2 * y2' equal to one
a2 = 3.6056

octave> x2 = x2/a2
x2 =

  -1.10940   0.27735

octave> y2 = y2/a2
y2 =

  -0.55470   1.38675

octave> x2 * y2' # x1 and x2 are biorthogonal to y1 and y2
ans = 1

octave> x2 * y1'
ans =  1.1059e-17

octave> x1 * y1'
ans = 1.0000

octave> x1 * y2'
ans =  -2.1792e-17

octave> A1 = 7 * (x1' * y1) # rank(A1) = 1
A1 =

   2.6923  10.7692
   1.0769   4.3077

octave> (A1 * x1')/7 - x1' # x1 is a right eigenvector of A1 w/eigenvalue 7
ans =

   4.4409e-16
   1.1102e-16

octave> (y1 * A1)/7 - y1 # y1 is a left eigenvector of A1 w/eigenvalue 7
ans =

   5.5511e-17   2.2204e-16

octave> A2 = -4 * (x2' * y2) # rank(A2) = 1
A2 =

  -2.46154   6.15385
   0.61538  -1.53846

octave> (A2 * x2')/-4 - x2' # x2 is a right eigenvector of A2 w/eigenvalue -4
ans =

  0
  0

octave> (y2 * A2)/-4 - y2 # y2 is a left eigenvector of A2 w/eigenvalue -4
ans =

   0.0000e+00   2.2204e-16

octave> A = A1 + A2 # rank(A) = 2
A =

   0.23077  16.92308
   1.69231   2.76923

octave> (A * x1')/7 - x1' # x1 is a right eigenvector w/eigenvalue 7
ans =

   4.4409e-16
   1.1102e-16

octave> (A * x2')/-4 - x2' # x2 is a right eigenvector w/eigenvalue -4
ans =

   -2.2204e-16
    0.0000e+00

octave> (y1 * A)/7 - y1 # y1 is a left eigenvector w/eigenvalue 7
ans =

   5.5511e-17   2.2204e-16

octave> (y2 * A)/-4 - y2 # y2 is a left eigenvector w/eigenvalue -4
ans =

  0  0

octave>