I keep getting NaN
74 views (last 30 days)
Show older comments
For some reason my T values keeps giving me NaN when putting greater values. I dont understand why the error occurs.
clc, clear all
T=0
summa=0;
x=60;%distance x=60 whole distance
s=0;
n=1%amount of steps (change this depending on the x)
route=input('1 or 2:')
%check approx anwser
fun= @(x) 1./(velocity(x,route));
check=60.*integral(fun,0,x) %in min
T=60.*time_to_destination(x,route,n)
while abs(check-T)>=1 %+-0.5 will give a span of 1
T=60.*time_to_destination(x,route,n); %in min
n=n+1;
end
svar=n %antal steg
t=T %integral approx värde (in min)
function T= time_to_destination(x,route,n)
s=0; %start vilkkor
summa=0;
h=x./n;
for i=0:h:x;
v=1./(velocity(s,route));
v2=1./(velocity((s+h),route));
summa=(h./2).*(v+v2)+summa; %trapets def
s=s+h;
end
T=summa;
end
6 Comments
Adam Danz
on 15 Sep 2020
That's helpful, Daniel Hodgson, but we need to be able to reproduce the NaN values on our end before we can trace back to their origins.
If there are any NaN values in the "v" output, please attach the two files.
If there aren't any NaN values in "v" you could produce v, save it to a mat file, and attach that mat file (or share the two files).
To determine if an array has any NaNs,
any(isnan(v),'all')
Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!