Shading an area between two curves symbolically

4 visualizaciones (últimos 30 días)
rezheen
rezheen el 16 de Jun. de 2025
Comentada: Star Strider el 17 de Jun. de 2025
I want to shade the area under the line y=2 and above the curve y=1+cos(x) from 0 to pi. I'm having trouble doing this. This is my code:
dy1 = 1+cos(x);
dy2 = 2;
fplot(dy1, [0 pi]); hold on;
fplot(dy2, [0 pi]);
patch([x fliplr(x)], [dy2 fliplr(dy1)], 'g');
hold off;

Respuesta aceptada

Star Strider
Star Strider el 16 de Jun. de 2025
It is necessary to get the relevant 'x' and 'y' values from the fplot calls first. You can then use them in the patch call.
Try this --
syms x
dy1 = 1+cos(x);
dy2 = 2;
figure
fp1 = fplot(dy1, [0 pi]);
hold on
fp2 = fplot(dy2, [0 pi]);
hold off
ylim('padded')
x1 = fp1.XData;
y1 = fp1.YData;
x2 = fp2.XData;
y2 = fp2.YData;
patch([x1 fliplr(x2)], [y1 fliplr(y2)], 'g');
hold off;
.

Más respuestas (0)

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by