How can I plot the region for two inequalities?

12 ビュー (過去 30 日間)
Matthew Morrison
Matthew Morrison 2016 年 7 月 28 日
コメント済み: Ayka 2022 年 12 月 14 日
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 件のコメント
Walter Roberson
Walter Roberson 2016 年 9 月 11 日
You should restore the original question here, and open a new question about fonts.
Rena Berman
Rena Berman 2016 年 10 月 30 日
(Answers dev) restored the original question

サインインしてコメントする。

採用された回答

Karan Gill
Karan Gill 2016 年 7 月 29 日
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
  7 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 19 日
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.*0; % multiply the two condaces to keep only the common points
surf(x,y,cond)
Image Analyst
Image Analyst 2021 年 4 月 19 日
The "cond" matrix is either 0 or nan, so why does it look curved/warped instead of flat?

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2016 年 7 月 29 日
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 件のコメント
Ming Zhen Ellis Tiew
Ming Zhen Ellis Tiew 2020 年 10 月 5 日
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!
Image Analyst
Image Analyst 2020 年 10 月 5 日
Try
axis ij;
after you've called imshow().

サインインしてコメントする。


Anna
Anna 2017 年 11 月 20 日
Is it possible to draw the region with a different color than black?
  1 件のコメント
Ayka
Ayka 2022 年 12 月 14 日
There are various ways. The most directy way is to construct the third dimension as the RGB color space and multiply the output by different values as the RGB value. For example, if you want to color the white center area to RGB(64,128,192), you can manipulate as
l = length(r);
colored_output = zeros(l,l,3);
colored_output(:,:,1) = output * 64; % 0 remains 0, 1 is amplified to 64
colored_output(:,:,2) = output * 128;
colored_output(:,:,3) = output * 192;
colored_output = uint8(colored_output); % Convert double to uint8 values
imshow(colored_output, 'xdata', r, 'ydata', r);
axis on
If you want to color the surrounding black area, you can just add values to the zero values like
output1 = output;
output1(output1 == 0) = 64;
colored_output(:,:,1) = output1;

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by