MATLAB: Finite difference problem showing NaN value

finite differencematlab function

closed

Best Answer

When M>=2, in the last line of your code,
Rt_inc(M+1)=(v-1)*(rt_inc(M)^2)*((rt_inc(M+1)-rt_inc(M))/dt)/Sr(M);
because rt_inc(M+1)-rt_inc(M)=0 and Sr(M)=0, this becomes 0/0, which is not defined and produces a NaN in Matlab.
Related Question