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 SolutionsMATLAB: Results showing up as NaN Here is one source of NaN's: In slipratio_fun with the initial value of t=0 and v=0, you have omega=v=0. The linesx (abs(omega)*r>=abs(v)) = -1 + v./(omega.*r); % accelerationsets sz equal to NaN because it's dividing by zero. MATLAB: Ignoring [NaN; NaN] if all(isnan(A)) A = B;elseif all(isnan(B)) B = A;end%proceed with A and B Related QuestionSorting NaN
Best Answer