Shading an area between two curves symbolically

4 次查看(过去 30 天)
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;

采纳的回答

Star Strider
Star Strider 2025-6-16
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;
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by