필터 지우기
필터 지우기

I keep getting NaN

조회 수: 74 (최근 30일)
Daniel Hodgson
Daniel Hodgson 2020년 9월 15일
댓글: Daniel Hodgson 2020년 9월 15일
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
Adam Danz
Adam Danz 2020년 9월 15일
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')
Daniel Hodgson
Daniel Hodgson 2020년 9월 15일
i really appreaciate the help. I beleive i have fixed the issue for the for loop i needed to change it to i=0:h:x-h as i was trying to calculate an integral using the trapezoidal method and i beleive i had exceeded the boundries of my integral by including x at to my understanding the x also breaks the methods rules.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by