Plotting the area defin

Iluating x & y, I don't want a & b to be always the same as long as 0<=a<=1 & 0<=b<=1. But I have no idea to resolve this issue!!

回答 (3 件)

John D'Errico
John D'Errico 2018 年 10 月 13 日

1 投票

You know how to use meshgrid! In fact, I know that, because you used it in your other question.
So it you want to plot something over all combinations of a and b, then why not use meshgrid? (10000 points in each dimensions will be wild overkill of course.)

5 件のコメント

Image Analyst
Image Analyst 2018 年 10 月 13 日
So he can use linspace() to reduce the number of points and get something like this:
numPoints = 50;
a=linspace(0, 1, numPoints);
b=linspace(0, 1, numPoints);
[a, b] = meshgrid(a,b);
x=a.^2-b.^2;
y=a.*b;
plot(x, y, '-', 'LineWidth', 2);
grid on;
xlabel('x', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
Sultan Al-Hammadi
Sultan Al-Hammadi 2018 年 10 月 13 日
The problem is that when evaluating x & y, I don't want a & b to be always the same as long as 0<=a<=1 & 0<=b<=1. But I have no idea to resolve this issue!!
madhan ravi
madhan ravi 2018 年 10 月 13 日
編集済み: madhan ravi 2018 年 10 月 13 日
You need to be clear in what you want to do? Still your statement is not clear
John D'Errico
John D'Errico 2018 年 10 月 13 日
編集済み: John D'Errico 2018 年 10 月 13 日
As I said, you resolve the issue by using meshgrid. meshgrid generates ALL combinations of the two variables, a & b.
[a,b] = meshgrid(0:.01:1,0:.01:1);
So a and b are now TWO dimensional arrays, here, each of size 101x101. Now compute x and y as directed.
x = a.^2 - b.^2;
y = a.*b;
plot(x,y,'.')
The result is a sort of triangular domain, with curved edges along the top.
Are you asking how to generate the boundary of that domain? From what you have said, I don't think so.
edgeind = convhull(x(:),y(:));
plot(x(edgeind),y(edgeind),'r-')
But you need to understand that when you want to generate all combinations of two variables like this, USE MESHGRID.
Sultan Al-Hammadi
Sultan Al-Hammadi 2018 年 10 月 14 日
Thank you so much, it looks quite right
Bruno Luong
Bruno Luong 2018 年 10 月 13 日
編集済み: Bruno Luong 2018 年 10 月 13 日

0 投票

almost right, you need to make a & b oriented in 2 different dimensions (here row for a and column for b)
a=linspace(0,1,101);
b=linspace(0,1,101)'; % <= make a column
x=a.^2-b.^2;
y=a.*b;
plot(x,y,'.b');

4 件のコメント

Sultan Al-Hammadi
Sultan Al-Hammadi 2018 年 10 月 13 日
The problem is that when evaluating x & y, I don't want a & b to be always the same. But I have no idea to resolve this issue!!
Bruno Luong
Bruno Luong 2018 年 10 月 13 日
編集済み: Bruno Luong 2018 年 10 月 13 日
you do not need to have same a and b, simply make them oriented differently
Sultan Al-Hammadi
Sultan Al-Hammadi 2018 年 10 月 13 日
Is there a way to get it every possible value of a & b, and hence evaluating all possible values of x & y? [for example, a could equal to 0.1 while b=1, etc]
Bruno Luong
Bruno Luong 2018 年 10 月 13 日
編集済み: Bruno Luong 2018 年 10 月 13 日
??? x, y are already computed from all combination of a, b with resolutions of 0.01.
So what your question is about? Might be your should slow down think, then ask a real question.
Bruno Luong
Bruno Luong 2018 年 10 月 13 日

0 投票

Or perhaps you want this?
a=linspace(0,1,100)';
b=linspace(0,1,100)';
rect = [a 0+0*a;
1+0*b b;
flip(a) 1+0*a;
0+0*b flip(b)];
a = rect(:,1);
b = rect(:,2);
x=a.^2-b.^2;
y=a.*b;
plot(x,y,'-b');

この質問は閉じられています。

タグ

質問済み:

2018 年 10 月 13 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by