我有函数 P ,它取两个点,如果满足某些条件则返回true,否则返回false。我想绘制满足条件的范围lx <= x <= hx, ly <= y <= hy
中的所有点。如何用scilab做到这一点?
答案 0 :(得分:0)
lx = 0;
hx = 10;
ly = 0;
hy = 10;
// Create x and y lists
a = linspace(lx,hx);
b = linspace(ly,hy);
// Create arrays for function evaluation on a 2D grid
[A,B] = ndgrid(a,b)
// Define your predicate as a function
function result = P(a, b)
result = (a < b);
endfunction
// Evaluate your function for all values in A and B and as a result
// get a matrix p filled with booleans
p = P(A(:),B(:));
// Find all indices of TRUE
indices = find(p);
// Plot all points using A as x coordinate and B as y coordinate
plot(A(indices), B(indices), 'o')
// Scale the axis of the plot so that all points are visible
a=gca();
a.data_bounds = [lx,ly;hx,hy];
这将产生以下情节: