필터 지우기
필터 지우기

Output is -INF

조회 수: 2 (최근 30일)
Marios Christofides
Marios Christofides 2020년 7월 5일
답변: dpb 2020년 7월 5일
I added a while loop to my code so that it would output the time with the data every .5 seconds as well as a mod funciton to only output every 100th result. I added this to my code and the output is only -INF for everything. Does anyone know how to fix it?
while t <= 12
t = t + .5;
for c = 1:1:nt
%Forward Euler Method
x1 = xi + dt*(a*xi*(1 - xi/20) - b*xi*yi - c*xi*zi);
y1 = yi + dt*(yi*(1-yi/25) - a*xi*yi - d*yi*zi);
z1 = zi + dt*(b*zi*(1-zi/30) - xi*zi - yi*zi);
xi = x1;
yi = y1;
zi = z1;
data = [t,xi, yi, zi];
if mod(c,100)==0
fprintf(1, '\t%d\t%06f\t%12.5E\t%.2f\n\n', data);
end
end
end
Time = toc

답변 (1개)

dpb
dpb 2020년 7월 5일
You had
...
x1 = xi + dt*(a*xi*(1 - xi/20) - b*xi*yi - c*xi*zi);
y1 = yi + dt*(yi*(1-yi/25) - a*xi*yi - d*yi*zi);
before with both c and d undefined in the posted code (as well as were a, b and other things...so those had to have been set in workplace before.
Now you've introduced and reused variable c for some other purpose -- that undoubtedly is at least part of the problem.
I recommend strongly pull all your code together in one script m-file; and make sure it's working again completely independently -- putting a function keyword at beginning would make it such that anything not defined in the function would be flagged...
Then, once you've got that working (again), then you can introduce some new counter variable...

카테고리

Help CenterFile Exchange에서 Utilities에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by