MATLAB doesn't give an answer for this Waterfall graph and runs this continuously, what's wrong with this?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yuvraaj Pasumarthy
am 11 Feb. 2024
Kommentiert: Yuvraaj Pasumarthy
am 11 Feb. 2024
a = linspace(0.01, 10, 4001);
r = linspace(0.1, 10, 4001);
for i = 1:numel(a)
for j = 1:numel(r)
X(i, j)=(a(i)*r(j)^2)/((r(j)^3)-(a(i))*r(j)+a(i));
end
end
figure;
waterfall(r, a, X');
xlabel('r');
ylabel('a');
zlabel('X');
title('3D Waterfall Plot for X=(a*r^2)/((r^3)-(a)*r+a)');
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 11 Feb. 2024
Bearbeitet: Walter Roberson
am 11 Feb. 2024
You need to vectorize
Reduced size here to fit within the time limits.
a = linspace(0.01, 10, 401);
r = linspace(0.1, 10, 401);
X = (a(:).*r.^2) ./ ((r.^3) - (a(:)) .* r + a(:));
figure;
waterfall(r, a, X');
xlabel('r');
ylabel('a');
zlabel('X');
title('3D Waterfall Plot for X=(a*r^2)/((r^3)-(a)*r+a)');
3 Kommentare
Walter Roberson
am 11 Feb. 2024
X has negative values. Log of negative values is complex, and waterfall cannot construct plots with complex coordinates.
In the below, I set those coordinates to NaN.
a = linspace(0.01, 10, 401);
r = linspace(0.1, 10, 401);
X = (a(:).*r.^2) ./ ((r.^3) - (a(:)) .* r + a(:));
figure;
Lx = log(X);
Lx(imag(Lx)~=0) = nan;
waterfall(r, a, Lx');
xlabel('r');
ylabel('a');
zlabel('X');
title('3D Waterfall Plot for X=(a*r^2)/((r^3)-(a)*r+a)');
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!