Hi,
In the while loop part of the code, mldivide(\) operator is used which has the same precedence as that of matrix multiplication(*). So, (BUCKLING(n-2)-BUCKLING(n-1))*(1-K(n-1)) becomes 0. Also the value of (K(n-2)-K(n-1)) is 0. Hence, it is of the form 0 \ 0 which is returning NaN. That is why there is a warning that "Matrix is singular, close to singular or badly scaled. Results may be inaccurate". If you change the line to:
BUCKLING(n)=BUCKLING(n-1)+(BUCKLING(n-2)-BUCKLING(n-1))*((1-K(n-1))\(K(n-2)-K(n-1)));
then this particular warning issue may get resolved. But still you will get BFinale=0 and RAGGIO=inf as the form of (BUCKLING(n-2)-BUCKLING(n-1))*((1-K(n-1))\(K(n-2)-K(n-1))) is still 1 \ 0 which will always return zero and the value of BUCKLING(n) will never increase for any value of n. Hence, it is recommended to check the code as well as the names of variables once again.