Gram Schmidt con R
Aquí hay un código MATLAB para realizar Gram Schmidt en la página 1http://web.mit.edu/18.06/www/Essays/gramschmidtmat.pdf
Estoy intentando durante horas y horas realizar esto con R ya que no tengo MATLAB Aquí está mi R
f=function(x){
m=nrow(x);
n=ncol(x);
Q=matrix(0,m,n);
R=matrix(0,n,n);
for(j in 1:n){
v=x[,j,drop=FALSE];
for(i in 1:j-1){
R[i,j]=t(Q[,i,drop=FALSE])%*%x[,j,drop=FALSE];
v=v-R[i,j]%*%Q[,i,drop=FALSE]
}
R[j,j]=max(svd(v)$d);
Q[,j,,drop=FALSE]=v/R[j,j]}
return(list(Q,R))}
Sigue diciendo que hay errores en:
v=v-R[i,j]%*%Q[,i,drop=FALSE]
o
R[j,j]=max(svd(v)$d);
¿Qué es lo que estoy haciendo mal al traducir el código MATLAB a R?