The problem is in how you construct x. This looks to me like a classic fencepost error problem, but it's compounded by the fact that you set N to the matrix size +1 and are using h for both the matrix calculations and the vector construction.
I'm confused as to why you set N to 10 and then always use N-1. Why not set N to 9 and just use N?
On that note, you'll have to change the terminal index for the error vector loop to N-2.