Q[j-2] gives you Q[0] in your first inner loop iteration. R arrays start at one.
B. > On 2018-06-13, at 07:21, Maija Sirkjärvi <maija.sirkja...@gmail.com> wrote: > > Amat[J-1+j-2,j-1]= 1/(Q[j] - Q[j-1]) + 1/(Q[j-1] - Q[j-2]) ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.