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

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!

 采纳的回答

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 个)

类别

标签

Community Treasure Hunt

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

Start Hunting!

Translated by