Clear Filters
Clear Filters

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

2 views (last 30 days)
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)');

Accepted Answer

Walter Roberson
Walter Roberson on 11 Feb 2024
Edited: Walter Roberson on 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 Comments
Walter Roberson
Walter Roberson on 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)');

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!