why range of x axis of time is not showing
2 views (last 30 days)
Show older comments
Tstart = 0.0;
Tend = 100.0;
Nt = 2000;
dT = (Tend-Tstart)/Nt;
X0 = 1;
Y0 = 2;
Z0 = 3;
N = 20;
k1=1
k2=3
k3=1
k4=5
I=0.5
s=4;
xr=-1.6;
r=0.0001;
% Initialize coefficient arrays
T = zeros(Nt+1,1);
X = zeros(Nt+1,1);
Y = zeros(Nt+1,1);
Z = zeros(Nt+1,1);
a = zeros(N+1,1);
b = zeros(N+1,1);
c = zeros(N+1,1);
T(1) = 0.0;
X(1) = X0;
Y(1) = Y0;
Z(1) = Z0;
for j = 2:Nt+1
a(1) = X(j-1);
b(1) = Y(j-1);
c(1) = Z(j-1);
for k = 1:N
a(k+1)=(b(k)-k1*a(k).^3+k2*a(k).^2-c(k)+I)/(k+1);
b(k+1)=(k3-k4*a(k).^2-b(k))/(k+1);
c(k+1)=r*(s*(a(k)-xr)-c(k))/(k+1);
end
x = a(1);
y = b(1);
z = c(1);
for k = 2:N+1
x = x + a(k)*dT^(k-1);
y = y + b(k)*dT^(k-1);
z = z + c(k)*dT^(k-1);
end
T(j) = T(j-1) + dT;
X(j) = x;
Y(j) = y;
Z(j) = z;
end
figure(1)
plot(T,X,'Color','red')
hold on
figure(2)
plot(T,Y,'Color','red')
hold on
figure(3)
plot(T,Z,'Color','red')
hold on
figure(4)
plot3(X,Y,Z,'Color','red')
hold on
the time range is coming 1.5 in
place of 100
1 Comment
Answers (2)
Walter Roberson
on 9 Mar 2022
Because after that your values go to infinity or nan. Automatic selection of plot axes range is based only on the finite coordinates of what is drawn.
2 Comments
Davide Masiello
on 9 Mar 2022
That's happening because all the values of X,Y, and Z after T = 1.5 are NaN, which will not be plotted by MatLab.
I guess there might be a mistake in your equations that causes them to predict your variables to be NaN.
12 Comments
Walter Roberson
on 15 Mar 2022
I had my program continue calculatign with symbolic Y0.
Before the end of the 7th j loop, some of the expressions involve Y0 to the power of over 320000, and coefficients over 10 to the million.
The arithmetic round-off involved in the calculations is horrible.
If your Y0 is anything with absolute value greater than 1 then for certain your values would explode beyond the range of double precision; if your Y0 is anything with absolute value less than 1, then most of the terms are going to underflow.
Walter Roberson
on 15 Mar 2022
I substituted in 10^-10 for Y0 in c(6) . The result was less than -2 times 10 to the one million.
There is just no possibility of getting useful numbers out of the equations you have given.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!