If you want to store y for each h, then you should be storing into y(h) and z(h) instead of into y(i+1) and z(i+1), and you would access y(h) instead of y(i+1) in calculating the Error.
What you had would work (but not be the best solution) if you incremented i after each iteration of the "for h" loop.
Note: you are not storing each individual Error value as you go, so it is only going to reflect the final h value, and so would not need to be calculated inside the loop if you only need the final value.
Best Answer