Plot the area of the surface

2 次查看(过去 30 天)
Atom
Atom 2023-8-16
评论: Atom 2023-8-19
Plot area of the surface that lies inside
The equation can be written in polar coordinate as $r^2=a^2 \sin(2\theta)$ which is a loop.
Please help me to plot the surface. Please highlight the portion of the surface by a color.

采纳的回答

Ruchika
Ruchika 2023-8-16
编辑:Ruchika 2023-8-16
Hi, you can use the 'surf' function to plot the surface in MATLAB and highlight the portion that lies inside the given equation. Following is the MATLAB code that accomplishes this:
% Define the range of theta
theta = linspace(0, 2*pi, 100);
% Define the value of a
a = 1; % Replace with the desired value
% Calculate the maximum value of r based on the given equation
r_max = a * sqrt(abs(sin(2*theta)));
% Create a meshgrid for theta and r
[Theta, R] = meshgrid(theta, linspace(0, max(r_max), 100));
% Convert polar coordinates to Cartesian coordinates
X = R.*cos(Theta);
Y = R.*sin(Theta);
Z = X.*Y;
% Create a figure and plot the surface
figure;
surf(X, Y, Z, 'EdgeColor', 'none');
% Set the color for the portion inside the given equation
inside_color = [0.8, 0.2, 0.2]; % Reddish color
% Highlight the portion inside the equation by setting color
Z_highlighted = Z;
Z_highlighted((X.^2 + Y.^2).^2 > 2*a^2*X.*Y) = NaN;
% Plot the highlighted portion
hold on;
surf(X, Y, Z_highlighted, 'FaceColor', inside_color, 'EdgeColor', 'none');
% Set the view and labels
view(3);
xlabel('X');
ylabel('Y');
zlabel('Z');
% Add a color bar to indicate the highlighted portion
colormap(gca, [inside_color; get(gca, 'color')]);
c = colorbar;
c.Label.String = 'Highlighted Portion';
% Adjust the plot settings
axis equal;
title('Surface Plot of az = xy');
Kindly replace 'a' with the desired value for the equation.
Please refer to the following documentation to know more about the 'surf' function :
  3 个评论
Ruchika
Ruchika 2023-8-16
Hi, the portion of the surface az = xy that lies inside the region defined by r^2 = a^2 * sin(2θ) is represented by the red surface in the plot.
In polar coordinates, the equation r^2 = a^2 * sin(2θ) represents a loop-shaped curve. The portion of the surface az = xy that lies inside this loop is highlighted in red in the plot.
Atom
Atom 2023-8-19
In this plot the cylindrical shape of (X.^2 + Y.^2).^2 = 2*a^2*X.*Y is missing. Would you modify the code so that one can visualize a transparent cylindrical shape. Your code visualizes the area of the given surface inside the cylinder.

请先登录,再进行评论。

更多回答(1 个)

Constantino Reyes-Aldasoro
This forum does not work like this. You have to try to do the coding first and when you run into problems, then you ask for help adding the coding that you have already done.
  2 个评论
Atom
Atom 2023-8-16
True, but I am unable to understand how to start.. In polar coordinate r^2=a^2 \sin(2\theta) will look like two loops... How to plot, I dont know really
John D'Errico
John D'Errico 2023-8-16
编辑:John D'Errico 2023-8-16
This is why, had I seen the question long ago, it would have been closed immediately. As now, the student thinks it is ok to post questions about homework, with no attempt made.
Not understanding how to do homework just means that a question should have been directed to the teacher. Or the students in the class could have discussed the problem amongst themselves. (That is how I survived one difficult class long ago.) And not being able to do a homework problem does not cost much.
Finally, I would point out that @Atom has posted and gotten away with 48 separate questions. Many of which seem to be like this. So I will now be forced to watch more carefully.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by