I wrote some code to insert a value along the diagonal of a matrix, but I can't figure out why it's giving me the error: fatal error: Index out of range
The code:
var tempHamil = [[Double]]()
var particleinboxHamil = [[Double]]()
let boxlength: Double = LengthOfBox
for i in 0...NumberEigenvalues-1{
for j in 0...NumberEigenvalues-1{
if i==j {
particleinboxHamil[i][j] = particleinboxenergy(ValueForN: i, LengthOfBox: box length)//error is thrown here
} else {
particleinboxHamil[i][j]=0.0
}
tempHamil = particleinboxHamil
}
}