source("findPoints.R")
Y <- genAllPoints(M=2)
#Y
U<-array(dim = c(dim(Y)[1], 2, 2) )
for( i in c(0,1)){
for( j in c(0,1)){
Uij<-genUijNew(Y,i,j)
for (k in c(1:dim(Y)[1])){
U[k, i+1,j+1]<-Uij[k,k]
}
}
}
# for (k in c(1:dim(Y)[1])){
# print(Y[k,])
# print(U[k,,])
# }
library("Matrix")
library('rARPACK')
Lmu<- genLmuNew(Y,mu=1)
N<-dim(Lmu)[1]
lam<-eigen(Lmu)$values
# L<- Lmu %o% matrix(c(1, 0, 0, 1), 2, 2, byrow=TRUE)
# Lmu
plot(x=c(1:N) , y=Re(lam))
Lmu[c(1,12,32),c(1,12,32)]
## [,1] [,2] [,3]
## [1,] 0-1.27324i 0+1.27324i 0+0.00000i
## [2,] 0+0.00000i 0-1.27324i 0+1.27324i
## [3,] 0+0.00000i 0-1.27324i 0+1.27324i
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
Ns<-c(10,30,50,70,90,200)
l<-list()
df<-data.frame("id"=c(0), "l"=c(0), "N"=c(0), "type"=c(0))
df<-df[-1,]
for (N in Ns){
a<-matrix(rep(0,N*N), nrow=N,ncol=N)
for(i in c(1:N)){
for(j in c(1:N)){
if(j==(i+1)%%N) a[i,j]<- 1
if(j==(i-1)%%N) a[i,j]<- 0
if(j==N && i==1) a[i,j]<- 0
if(j==N && i==N-1) a[i,j]<-1
a[i,i]<- -1
}
}
a<--1i*a/2
a2<- (a+Conj(t(a)))
a2<- a2%*%a2
l<-eigen(a2)$values[N:1]
df<-rbind(df,data.frame("id"=c(1:N), "l"=l, "N"=rep(N,N), "type"=rep("(a+ad)",N) ))
a2<- a%*%Conj(t(a))
l<-eigen(a2)$values[N:1]
df<-rbind(df,data.frame("id"=c(1:N), "l"=l, "N"=rep(N,N), "type"=rep("(a*ad)",N) ))
}
gg<-ggplot(df)+theme_bw()
gg<- gg+ geom_point(aes(x=id, y=l, shape=as.factor(type), color=as.factor(N) ))
gg<- gg+scale_shape_manual(values=c(5,3))
fig<-ggplotly(gg)
fig
#print(htmltools::tagList(fig))
Ns<-c(10,30,50,70,90,200)
l<-list()
count<-1
df<-data.frame("id"=c(0), "l"=c(0), "N"=c(0))
df<- df[-1,]
for (N in Ns){
a<-matrix(rep(0,N*N), nrow=N,ncol=N)
for(i in c(1:N)){
for(j in c(1:N)){
if(j==(i+1)%%N) a[i,j]<- 1
if(j==(i-1)%%N) a[i,j]<- -1
if(j==N && i==1) a[i,j]<- -1
if(j==N && i==N-1) a[i,j]<- 1
}
}
# a-Conj(t(a))
# print(a)
a<- -1i*a/2
a2<- a%*%a
l<-eigen(a2)$values[N:1]
df<-rbind(df,data.frame("id"=c(1:N), "l"=l, "N"=rep(N,N) ))
# plot(x=c(1:N) , y=l[[count]])
# count<- count+1
}
gg<-ggplot(df)+theme_bw()
gg<- gg+ geom_point(aes(x=id, y=l, color=as.factor(N), shape=as.factor(N) ))
gg<- gg#+xlim(0,40)
fig<-ggplotly(gg)
fig
Here we want to check what happen to the eigenvalues of \(\hat P^2=(-id/dx)\) when we discretise the derivative mixing randomly forward and backward derivatives at each point
library(ggplot2)
library(plotly)
forward_deriv_row<-function(i,N){
row<-rep(0,N)
for(j in c(1:N)){
if(j==(i+1)%%N) row[j]<- 1
if(j==(i-1)%%N) row[j]<- 0
if(j==N && i==1) row[j]<- 0
if(j==N && i==N-1) row[j]<- 1
}
row[i]<- -1
return(row)
}
backward_deriv_row<-function(i,N){
row<-rep(0,N)
for(j in c(1:N)){
if(j==(i+1)%%N) row[j]<- 0
if(j==(i-1)%%N) row[j]<- -1
if(j==N && i==1) row[j]<- -1
if(j==N && i==N-1) row[j]<- 0
}
row[i]<- 1
return(row)
}
Ns<-c(10,30,50,70,90,200)
l<-list()
df<-data.frame("id"=c(0), "l"=c(0), "N"=c(0), "type"=c(0))
df<-df[-1,]
for (N in Ns){
a<-matrix(rep(0,N*N), nrow=N,ncol=N)
for(i in c(1:N)){
r<-runif(1)
if(r<0.5) a[i,]<-forward_deriv_row(i,N)
else a[i,]<-backward_deriv_row(i,N)
}
a<- -1i*a/2
a2<- a+Conj(t(a))
a2<- a2%*%a2
l<-eigen(a2)$values[N:1]
df<-rbind(df,data.frame("id"=c(1:N), "l"=l, "N"=rep(N,N), "type"=rep("(a+ad)",N) ))
a2<- a%*%Conj(t(a))
l<-eigen(a2)$values[N:1]
df<-rbind(df,data.frame("id"=c(1:N), "l"=l, "N"=rep(N,N), "type"=rep("(a*ad)",N) ))
}
gg<-ggplot(df)+theme_bw()
gg<- gg+ geom_point(aes(x=id, y=l, shape=as.factor(type), color=as.factor(N) ),
)
gg<- gg+scale_shape_manual(values=c(5,3))
fig<-ggplotly(gg)
fig
Here we choose: - forward derivative for the \(x \mod 2=1\) - backward derivative for the \(x \mod 2=0\)
Ns<-c(10,30,50,70,90,200)
l<-list()
df<-data.frame("id"=c(0), "l"=c(0), "N"=c(0), "type"=c(0))
df<-df[-1,]
for (N in Ns){
a<-matrix(rep(0,N*N), nrow=N,ncol=N)
for(i in c(1:N)){
if(i%%2==1) a[i,]<-forward_deriv_row(i,N)
else a[i,]<-backward_deriv_row(i,N)
}
a<- -1i*a/2
a2<- a+Conj(t(a))
a2<- a2%*%a2
l<-eigen(a2)$values[N:1]
df<-rbind(df,data.frame("id"=c(1:N), "l"=l, "N"=rep(N,N), "type"=rep("(a+ad)",N) ))
a2<- a%*%Conj(t(a))
l<-eigen(a2)$values[N:1]
df<-rbind(df,data.frame("id"=c(1:N), "l"=l, "N"=rep(N,N), "type"=rep("(a*ad)",N) ))
}
gg<-ggplot(df)+theme_bw()
gg<- gg+ geom_point(aes(x=id, y=l, shape=as.factor(type), color=as.factor(N) ),
)
gg<- gg+scale_shape_manual(values=c(5,3))
fig<-ggplotly(gg)
fig