Effacer les filtres
Effacer les filtres

MATLAB doesn't give an answer for this Waterfall graph and runs this continuously, what's wrong with this?

2 vues (au cours des 30 derniers jours)
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)');

Réponse acceptée

Walter Roberson
Walter Roberson le 11 Fév 2024
Modifié(e) : Walter Roberson le 11 Fév 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 commentaires
Walter Roberson
Walter Roberson le 11 Fév 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)');

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by