Similar to JTK I can' see any problem here as the routine seems to work OK. I also don't understand what exactly you mean with " it starts from the second value in the matrix not from the first value".
What I notice is:
1) You formulate the calculation as a function but actually it isn't a function. The argument Z you provide has no effect! You could as well define LayerI as a normal variable!

Luc suspected hat you meant "z" as argument instead if "Z", but I thinks thats not the case as you define other variables in a very similar way as functions later in your sheet. You probably thinks that you have to provide the return variable "Z" in some way, but thats not the case. As soon as you use it in your program, its created.
2) The program looks for a specific range in a vector " z' " and returns the corresponding values from the vector " z ". But z an z' are the very same vectors just with different signs as you have defined z := z' somewhere above. Why?
You could achieve the very same effect easier using just vector z' and the "vlookup" function (Note the minus sign in front of "vlookup", which ensures the desired sign change)

If z and z' would be significantly different vectors, you could use the "lookup" function as shown here

To make clear what happens and why the function works OK (at least thats what I think), you can make the calculations on worksheet level and check intermediate results:

As you can see, the 0.26m in row #14 is the first value which is in the range from 0.245 m to 1.4 m.
So why do you think that the program "starts from the second value in the matrix not from the first value" ??