Plotting an exponential exp(-x), in 3D?

Hi, I want to plot exp(-x) which is e^-x, and revolve it around x=-5 in order to get a 3D solid that looks like a cooling tower of nuclear power plants. However the limit of y values should be from 1 to 200 which the height of the tower. How can I do that?
Thanks!

 Accepted Answer

Try this:
r = linspace(0.5, 5, 50);
a = linspace(0, 2*pi, 60);
[R,A] = ndgrid(r,a);
Z = exp(-R);
[X,Y,Z] = pol2cart(A,R,Z);
figure
mesh(X, Y, Z)
grid on
producing:
.Experiment to get it to look the way you want it to look.

16 Comments

How can I remove that big circle on the bottom? I mean y values should start from 1 to 200.
Try this slightly revised version:
sval = 2.5; % Shape Factor
hval = 800; % Height Factor
inner_rad = 0.5; % Inner Radius (Top)
outer_rad = 1.1; % Outer Radius (Base)
r = linspace(inner_rad, outer_rad, 50);
a = linspace(0, 2*pi, 60);
[R,A] = ndgrid(r,a);
Z = hval*exp(-R*sval);
[X,Y,Z] = pol2cart(A,R,Z);
figure
mesh(X, Y, Z)
grid on
Change ‘sval’ and ‘hval’ and the other parameters to get the result you want.
.
Thank you very much! This is what I need. Appreciate it!🙌
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
I was wondering if you could put comments for each line of code, so then I would be able to explain this code during the presentation. Thank you!
I am not certain what you want.
This is the best I can do:
sval = 2.5; % Shape Factor (Determines Vertical Curvature)
hval = 800; % Height Factor (Determines Maximum Vertical Height)
inner_rad = 0.5; % Inner Radius (Top)
outer_rad = 1.1; % Outer Radius (Base)
r = linspace(inner_rad, outer_rad, 50); % Define Radius (Vector)
a = linspace(0, 2*pi, 60); % Define Angle In Radians (Vector)
[R,A] = ndgrid(r,a); % Create Matrices For 3D Plot From Radius Vector & Angle Vector
Z = hval*exp(-R*sval); % Calculate Cooling Tower Shape (Matrix)
[X,Y,Z] = pol2cart(A,R,Z); % Convert Polar Matrices To Cartesian Matrices For 3D Plot
figure % Create Figure Window
mesh(X, Y, Z) % Create ‘mesh’ Plot Of 3D Cooling Tower
grid on % Create Grid Lines On All Axes
I would appreciate it if you would Accept my Answer.
.
Thank you very much! I was looking where I could accept it, so now I found it and accepted it!🙌😊
One more question. If you don't mind, could you please plot 2D graph of it as shown in the picture that I uploaded along with the original question. Thank you!
Thank you!
The easiest way to do that is to simply rotate the mesh plot:
figure % Create Figure Window
mesh(X, Y, Z) % Create ‘mesh’ Plot Of 3D Cooling Tower
grid on % Create Grid Lines On All Axes
view(90,0)
That is likely as close as it is possible to get.
Is it possible to revolve it around vertical line x=-25? Currently it revolves around vertical line x=0
Experiment with the view call to get the result you want:
view(90,25)
In the figure GUI, in the Tools drop-down menu, click on Rotate 3D. You can then use the mouse to rotate the figure until you get it the way you want it. The azimuth and elevation appear in the lower left corner of the figure GUI as you do this. Copy those as arguments to the view function to define those as your preferred view.
.
I am looking for something like this, shown in the picture. Pfofile view in terms of (x, y). Simple and clean graph.
Try this:
figure % Create Figure Window
mesh(X, Y, Z, 'FaceAlpha',0.2) % Create ‘mesh’ Plot Of 3D Cooling Tower
hold on % More Plots On Same Axes: On
zlvl = [100; 150; 200]; % Z-Levels For Disks
for k = 1:numel(zlvl)
zht = find(hval*exp(-r*sval)<=zlvl(k),1,'first'); % Z-Level Closest Index
patch(X(zht,:), Y(zht,:), Z(zht,:), 'r') % Draw Disk
end
plot3(X(1,:), Y(1,:), Z(1,:), 'k') % Top Circle
plot3(X(end,:), Y(end,:), Z(end,:), 'k') % Base Circle
hold off % More Plots On Same Axes: Off
grid on % Create Grid Lines On All Axes
view(90,10) % Define Camera Position
Experiment to get the result you want.
.
Perfect! Thank you very much!🙌
As always, my pleasure!

Sign in to comment.

More Answers (1)

exp(-x) does not seem to be a good function for this. Try following code
[X, Y] = meshgrid(-1:0.01:1);
XY = sqrt(X.^2 + Y.^2);
Z = 1./XY;
surf(X, Y, Z)
zlim([0 10])
caxis([0 10])
shading interp

1 Comment

I am doing a project, I have to use exp(-x), plus there shouldn't be th down surface it should be just a solid. Is there any other options?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!