Skip to content
Back to formatted view

Raw Message

Message-ID: <5569DDA1.2060702@hermes.cam.ac.uk>
Date: 2015-05-30T15:56:17Z
From: Michelle Morters
Subject: zero in alternate elements in alternate rows in matrix
In-Reply-To: <5569D6B2.90207@hermes.cam.ac.uk>

Hi - I'm trying to generate the (toy) matrix below in R. I get the error 
message shown below (and no matrix!) and I'm unclear as to why - if 
someone could advise as to why, that would be ace. Thank you! Michelle


0.7 	0 	0.1 	0 	0.1 	0 	0 	0 	0 	0 	0 	0
0.1 	0.7 	0.1 	0.1 	0.1 	0.1 	0 	0 	0 	0 	0 	0
0.1 	0.1 	0.7 	0 	0.1 	0 	0.1 	0 	0 	0 	0 	0
0.1 	0.1 	0.1 	0.7 	0.1 	0.1 	0.1 	0.1 	0 	0 	0 	0
0.1 	0.1 	0.1 	0.1 	0.7 	0 	0.1 	0 	0.1 	0 	0 	0
0 	0.1 	0.1 	0.1 	0.1 	0.7 	0.1 	0.1 	0.1 	0.1 	0 	0
0 	0 	0.1 	0.1 	0.1 	0.1 	0.7 	0 	0.1 	0 	0.1 	0
0 	0 	0 	0.1 	0.1 	0.1 	0.1 	0.7 	0.1 	0.1 	0.1 	0.1
0 	0 	0 	0 	0.1 	0.1 	0.1 	0.1 	0.7 	0 	0.1 	0
0 	0 	0 	0 	0 	0.1 	0.1 	0.1 	0.1 	0.7 	0.1 	0.1
0 	0 	0 	0 	0 	0 	0.1 	0.1 	0.1 	0.1 	0.7 	0
0 	0 	0 	0 	0 	0 	0 	0.1 	0.1 	0.1 	0.1 	0.7



cross = 0.1
diag = 0.7
n=12  # to be changed to n=1:100 once the code below is correct
nbe=4
R0=sapply(n,function(x){
m = matrix(0, nrow=x, ncol=x)
for (i in 1:x)
{
for(j in 1:x)
{
if (i==j)
{
m[i,j] = diag
}
else if(j<=i+nbe & j>=i-nbe)
{
m[i,j]=cross
}
}
}
for (i in seq(1,x,2))
{
for (j in seq(i+1,i+nbe,2))
{
m[i,j]=0
}
}
print(m)
max(Mod(eigen(m)$value))
}
)
R0

error message: Error in `[<-`(`*tmp*`, i, j, value = 0) : subscript out 
of bounds










	[[alternative HTML version deleted]]