Shading an area between two curves symbolically
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
rezheen
le 16 Juin 2025
Commenté : Star Strider
le 17 Juin 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;
0 commentaires
Réponse acceptée
Star Strider
le 16 Juin 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;
.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
