Plotting Inequalities in Matlab

285 visualizaciones (últimos 30 días)
John Buethe
John Buethe el 28 de Jun. de 2022
Comentada: John Buethe el 28 de Jun. de 2022
Hey all,
I have to plot some inequalities for a controls assignment for school and I was wondering if you all could help me.
The inequalities are:
x > 0
y > 5/x
y > (x^(2)-25)/5*x
Right now my code looks like this:
figure (3); clf
[x,y] = meshgrid(-10:0.02:10, -10:0.02:10);
ineq = (x > 0) & (y > 5./x) & (y > (x.^(2)-25)./(5*x));
x(~ineq) = NaN;
y(~ineq) = NaN;
plot(x(:),y(:)); box on; grid on;

Respuesta aceptada

KSSV
KSSV el 28 de Jun. de 2022
Editada: KSSV el 28 de Jun. de 2022
x = -10:0.1:10 ;
y = -10:0.1:10 ;
[X,Y] = meshgrid(x,y);
ineq = (X > 0) & (Y > 5./X) & (Y > (X.^(2)-25)./(5*X));
h = pcolor(X,Y,double(ineq)) ;
h.EdgeColor = 'none' ;
If you want to display on the region which satisfies.
x = -10:0.1:10 ;
y = -10:0.1:10 ;
[X,Y] = meshgrid(x,y);
ineq = (X > 0) & (Y > 5./X) & (Y > (X.^(2)-25)./(5*X));
ineq = double(ineq) ;
ineq(ineq==0) = NaN ;
h = pcolor(X,Y,double(ineq)) ;
h.EdgeColor = 'none' ;

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by