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

1 vue (au cours des 30 derniers jours)
F
F le 15 Sep 2014
Commenté : Star Strider le 18 Sep 2014
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!

Réponse acceptée

Star Strider
Star Strider le 16 Sep 2014
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.

Plus de réponses (1)

F
F le 18 Sep 2014
It worked fine!!
Thaaanks! ;)
  1 commentaire
Star Strider
Star Strider le 18 Sep 2014
My pleasure!

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by