绘制的所有点的集合满足的属性MATLAB
问题描述:
我要提请设定满足一个条件,例如点:绘制的所有点的集合满足的属性MATLAB
{(x,y) : x+y = 1}
或{(x,y) : -xlog(x)-ylog(y)>10}
或{(x,y,z) : x + yz^2 < 2}
(或任何其它属性)。
我找不到如何在matlab中绘制这些东西(我只找到了如何绘制函数,无法找到如何绘制平原)。任何帮助将受到欢迎。
谢谢
答
平等和不平等条件是两个根本不同的问题。
在等于的情况下,您将值赋予x
并解决y
。在您的例子:
x = linspace(-10,10,1000); %// values of x
y = 1-x; %// your equation, solved for y
plot(x,y, '.', 'markersize', 1) %// plot points ...
plot(x,y, '-', 'linewidth', 1) %// ... or plot lines joining the points
对于不平等你产生的x
,y
点(使用ndgrid
例如)网格,只保留那些满足您的条件。在您的例子:
[x, y] = ndgrid(linspace(-10,10)); %// values of x, y
ind = -x.*log(x)-y.*log(y)>10; %// logical index for values that fulfill the condition
plot(x(ind), y(ind), '.'); %// plot only the values given by ind
对于3D的想法是一样的,但是你用plot3
的绘图。在这种情况下,该组的形状可能更难从图中看出。在您的例子:
[x y z] = ndgrid(linspace(-10,10,100));
ind = x + y.*z.^2 < 2;
plot3(x(ind), y(ind), z(ind), '.', 'markersize', 1);
非常感谢您! – 2014-10-11 08:16:16