MATLAB Answers

How can I plot the region for two inequalities?

878 views (last 30 days)
I'm looking to plot the two inequalities for the formula: abs(x+y+x.^2<3) and abs(y+x+y.^2<3)
with them both being on the same plot. How would I go about doing this please? Or any other similar example is fine.
Thanks in advance

  2 Comments

Walter Roberson
Walter Roberson on 11 Sep 2016
You should restore the original question here, and open a new question about fonts.
Rena Berman
Rena Berman on 30 Oct 2016
(Answers dev) restored the original question

Sign in to comment.

Accepted Answer

Karan Gill
Karan Gill on 29 Jul 2016
Here's how to numerically evaluate the conditions and visualize them.
v = -5:0.01:5; % plotting range from -5 to 5
[x y] = meshgrid(v); % get 2-D mesh for x and y
cond1 = x+y+x.^2 < 3; % check conditions for these values
cond2 = y+x+y.^2 < 3;
cond1 = double(cond1); % convert to double for plotting
cond2 = double(cond2);
cond1(cond1 == 0) = NaN; % set the 0s to NaN so they are not plotted
cond2(cond2 == 0) = NaN;
cond = cond1.*cond2; % multiply the two condaces to keep only the common points
surf(x,y,cond)
view(0,90) % change to top view

  2 Comments

Image Analyst
Image Analyst on 29 Jul 2016
Or, more directly:
v = -5:0.01:5; % plotting range from -5 to 5
[x, y] = meshgrid(v); % get 2-D mesh for x and y
conditions = (x + y + x.^2 < 3) & (y + x + y.^2 < 3);
cond = zeros(length(v)); % Initialize
cond(conditions) = NaN;
surf(x, y, cond)
view(0,90)
TARIQ MOUSSAMIH
TARIQ MOUSSAMIH on 21 Nov 2017
I'm looking to plot a system of inequalities in 3-D (ax+by+cz<d). How would I go about doing this please? Thanks in advance

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 29 Jul 2016
You could do this:
r = -5:0.01:5; % plotting range from -5 to 5
[x, y] = meshgrid(r); % Get 2-D mesh for x and y based on r
condition1 = x+y+x.^2 < 3;
condition2 = y+x+y.^2 < 3;
output = ones(length(r)); % Initialize to 1
output(~(condition1 & condition2)) = 0; % Zero out coordinates not meeting conditions.
imshow(output, 'xdata', r, 'ydata', r); % Display
axis on;

  2 Comments

Ming Zhen Ellis Tiew
Ming Zhen Ellis Tiew on 5 Oct 2020
Good afternoon, I was wonder is that possible to let the y-axis start form -5 to 5 (because the picture is 5 to -5)? Thank you!

Sign in to comment.


Anna
Anna on 20 Nov 2017
Is it possible to draw the region with a different color than black?

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!