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;
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!