Output is -INF
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
dpb
el 5 de Jul. de 2020
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...
0 comentarios
Ver también
Categorías
Más información sobre Utilities en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!