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

2 次查看(过去 30 天)
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)');

采纳的回答

Walter Roberson
Walter Roberson 2024-2-11
编辑:Walter Roberson 2024-2-11
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 个评论
Walter Roberson
Walter Roberson 2024-2-11
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)');

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by