绘制满足谓词 scilab 的所有点

Plot all points that statisfy a predicate scilab

我有函数P,它取两个点,returns 如果它们满足某些条件则为真,否则为假。我想绘制 lx <= x <= hx, ly <= y <= hy 范围内满足条件的所有点。如何在 scilab 中执行此操作?

ndgrid and the find 函数的组合非常适合这个。例如:

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];

这将导致下图: