color area between functions

3 次查看(过去 30 天)
Hi,
I have two functions g = exp(-x.^2./2) and h = x.^2-3.*x+2;
there is a region enclosed between them, between x=0 and x=3
I wanna color it using fill
how to? =)

采纳的回答

David Hill
David Hill 2020-10-28
x = -1:.01:4;
g = exp(-x.^2./2);
h = x.^2-3.*x+2;
plot(x, g, 'r', 'LineWidth', 2);
hold on;
plot(x, h, 'b', 'LineWidth', 2);
x=.43:.01:2.08;
x2 = [x, fliplr(x)];
g = exp(-x.^2./2);
h = x.^2-3.*x+2;
inBetween = [g, fliplr(h)];
fill(x2, inBetween, 'g');

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by