## Gram-schmidt

November 4, 2014 Leave a comment

Matrix M has three rows and three columns, and the columns form an orthonormal basis. One of the columns is [2/7,3/7,6/7], and another is [6/7, 2/7, -3/7]. Let the third column be [x,y,z]. Since the length of the vector [x,y,z] must be 1, there is a constraint that x2+y2+z2 = 1. However, there are other constraints, and these other constraints can be used to deduce facts about the ratios among x, y, and z. Compute these ratios, and then identify one of them in the list below.

I viewed the Khan academy course.

But the credit for the Matlab code goes to Vladd. I didn’t follow his explanation but the Khan academy course helped.I used the Matlab online compiler to test Vladd’s code and ported it to R.

I can’t believe the *for* and *if* loops in the R code took a full day to debug.

# TODO: Add comment # # Author: radhakrishnan ############################################################################### A = matrix(c(2/7,3/7,6/7,6/7,2/7,-3/7,1,2,3),ncol=3,nrow=3) r = dim( A)[[1]]; c = dim( A)[[2]]; print(A) Q = matrix(c(0,0,0,0,0,0,0,0,0),ncol=3,nrow=3) for (j in 1:3){ u = matrix(A[ ,j ]); if( j - 1 != 0 ){ for(i in 1:(j - 1)){ e = Q[,i] a = as.matrix(A[,j]) p = (t(e) %*% a) / (t(e) %*% e) * e; u = u - p } } # normalize it to length of 1 and store it Q[,j] = u / sqrt(u[1,1]^2 + u[2,1]^2 + u[3,1]^2); print(Q) }

The result is this. The last column is what I want and that satisfies all constraints.

### Orthonormality

I will check-in the *R* code* *into my Git repository.