2014-10-10 94 views
1

我要提請設定滿足一個條件,例如點:繪製的所有點的集合滿足的屬性MATLAB

{(x,y) : x+y = 1}{(x,y) : -xlog(x)-ylog(y)>10}{(x,y,z) : x + yz^2 < 2} (或任何其它屬性)。

我找不到如何在matlab中繪製這些東西(我只找到了如何繪製函數,無法找到如何繪製平原)。任何幫助將受到歡迎。

謝謝

回答

3

平等和不平等條件是兩個根本不同的問題。

等於的情況下,您將值賦予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 

enter image description here

對於不平等你產生的xy點(使用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 

enter image description here

對於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); 

enter image description here

+0

非常感謝您! – 2014-10-11 08:16:16

相關問題