# Plot the area of the surface

3 views (last 30 days)

Show older comments

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.

##### 0 Comments

### Accepted Answer

Ruchika
on 16 Aug 2023

Edited: Ruchika
on 16 Aug 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 Comments

Ruchika
on 16 Aug 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.

### More Answers (1)

Constantino Reyes-Aldasoro
on 16 Aug 2023

##### 2 Comments

John D'Errico
on 16 Aug 2023

Edited: John D'Errico
on 16 Aug 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.

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!