正規直交基底行列は回転

  • 予定パッケージ名
    • SphereAndSimplex
  • 関数名
    • NormalBase
  • タイトル
NormalBase
  • 説明
回転行列(正規直交基底)をランダムに作る
  • 使用例
NormalBase(4)
  • ソース
# 回転行列を作る
NormalBase<-function(n){ # n次元
	I<-X<-diag(rep(1,n))
# ペアワイズに適当な角度を定める
	thetas<-runif(n*(n-1)/2)*2*pi
	T<-matrix(0,n,n)
	T[lower.tri(T)]<-thetas
# ペアワイズに適当に回転させることを全ペアについて実施
	for(i in 1:(n-1)){
		for(j in (i+1):n){
			R<-I
			R[i,i]<-R[j,j]<-cos(T[j,i])
			R[i,j]<-sin(T[j,i])
			R[j,i]<--R[i,j]
			X<-R%*%X
		}
	}
	X
}
  • Rdファイル
\name{NormalBase}
\alias{NormalBase}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
NormalBase
}
\description{
makes random nxn rotation matrix 
回転を表すnxn行列を作る
}
\usage{
NormalBase(n)
}
%- maybe also 'usage' for other objects documented here.
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
nxn matrix representing a rotation in n-dimensional space
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
%%  ~~who you are~~
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
n<-6
nb<-NormalBase(n)
# norm and inner product of pairs
e.out<-eigen(nb)
Mod(e.out[[1]]) # 回転行列の特異値分解は伸縮成分が1
# 回転の具合をプロット
# 回転行列の回転は、M=VSV* のSの部分のべき乗によって実行できる
T<-1000
dt<-2*pi/100
x<-matrix(0,T,n)
x[1,]<-runif(n)
for(i in 2:T){
	x[i,]<-e.out[[2]]%*%diag(e.out[[1]]^(dt*(i-1)))%*%solve(e.out[[2]]) %*% x[1,]

}
library(rgl)
plot3d(x[,1],x[,2],x[,3])
plot(as.data.frame(x))
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line