How To plot areas like: f(x) > mx +b ???

1 次查看(过去 30 天)
Hi everyone,
I'm trying to plot functions directly from FPLOT...
For instance:
fplot(@(x)10*x, [-10 10]);
BUT How can i plot "filled" graphs to indicate f(x)>10x or f(x)<10x
Thanks in advance!

采纳的回答

Star Strider
Star Strider 2014-9-16
You can’t do it with fplot but you can with patch:
x = linspace(0, 10, 2);
f1 = @(p,x) p(1).*x + p(2);
b1 = [0.7 1.0];
fv1 = f1(b1,x);
x1p = [x(1) x(2) x(2) x(1)]';
y1p = [fv1(1) fv1(2) fv1(2) fv1(2)]';
figure(1)
hp = patch(x1p, y1p, [0.1 0.1 0.9]);
axis([0 10 0 max(y1p)])
text(3, 5, '\bff(x) > 0.7 x + 1\rm', 'Color','r')
f2 = @(p,x) p.*x;
b2 = 10;
fv2 = f2(b2,x);
x2p = [x(1) x(2) x(2) x(1)]';
y2p = [fv2(1) fv2(1) fv2(2) fv2(1)]';
figure(2)
hp = patch(x2p, y2p, [0.1 0.9 0.1]);
axis([0 10 0 max(y2p)])
text(5, 20, '\bff(x) < 10 x\rm', 'Color','b')
Note the difference in order between ‘y1p’ and ‘y2p’ to get the ‘greater than’ and ‘less than’ respectively. (The vectors in [brackets] in the patch argument list are colour vectors.) Experiment with patch to appreciate what it can do.

更多回答(1 个)

F
F 2014-9-18
It worked fine!!
Thaaanks! ;)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by