Plot the area of the surface

2 visualizaciones (últimos 30 días)
Atom
Atom el 16 de Ag. de 2023
Comentada: Atom el 19 de Ag. de 2023
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.

Respuesta aceptada

Ruchika
Ruchika el 16 de Ag. de 2023
Editada: Ruchika el 16 de Ag. de 2023
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 comentarios
Ruchika
Ruchika el 16 de Ag. de 2023
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 el 19 de Ag. de 2023
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.

Iniciar sesión para comentar.

Más respuestas (1)

Constantino Reyes-Aldasoro
Constantino Reyes-Aldasoro el 16 de Ag. de 2023
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 comentarios
Atom
Atom el 16 de Ag. de 2023
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 el 16 de Ag. de 2023
Editada: John D'Errico el 16 de Ag. de 2023
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by