Well, you're trying to reach n + 1 when creating the B vector.
But n is 3. Thus your for loop goes until 4.
The problem is that dy_v has only 2 elements. Your loop is going from 1 to 4 while dy_v(i) is going from 1 to 2. That's the problem.
You mentioned the middle values of dy_v are NaN.
I declared dy_v = [0.33, NaN, NaN, -1.5] and the code worked.
Not sure if the math make sense by doing this, I didn't go through it.
If that helps, please accept the answer.