I have some inequality related to {x, y}
, which satisfies the following equations Is:
/ P>
x> = 0 y & gt; = 0 f (x, y) = x ^ 2 + y ^ 2> = 100 grams (x, y) = x ^ 2 + y ^ 2 & lt; = 200
Note that the x
and y
should be an integer.
Graphically it can be represented in the following ways, the blue area is the area that satisfies the above inequalities:
The question now is, is there any work in Matlab which is {x, y} < Finds each acceptable pair of / code>? If there is an algorithm for this kind of talk then I would be happy to hear about it too.
Of course, we can always use it to have an approach brutal force approach where we are satisfied with the inequalities or not to see that we can do everything possible to
{x, y}
Examine the combination. But this is the last resort, because it takes time. I'm looking for a clever algorithm that does this, or in the best case, an existing library that I can use directly-away
x ^ 2 + y ^ 2 & Gt; = 100
and x ^ 2 + y ^ 2 and lt; = 200
are just examples; In fact, f
and g
can be polynomial functions of any degree
Edit: C # code is also welcome .
This is certainly not possible for the general set of majority inequalities , In any way other than mathematical discovery, even if there is a limited number of solutions. (Maybe I should not be difficult to say, because it is possible. Countless searches will work, on the issue of floating point.) Note that the domain of interest should not be connected only for higher order disparities.
EDIT: OP has asked how anyone can proceed to search.
Consider the problem
x ^ 3 + y ^ 3 & gt; = 1e12 x ^ 4 + y ^ 4 & lt; = 1e16 x> = 0, y & gt; = 0
Resolve all integer solutions to this system Note that integer programming will not be enough in any form, because all integer solutions are requested.
Here the use of meshgrid us (0: 10000) X (0: 10000). So it forces us to sample a set of 1e8 digits, examines every point to see if they satisfy the obstacles.
A simple loop might possibly be more efficient than it, though it still will require some effort
% Note that I will store these in a cell array , Because I could not put the result in advance Tick xmx = 10000; Xy = cell (1, xmax); For X = 0: solution for xmax% y, given x, we need to solve% for those values of y which is% y ^ 3 & gt; = 1e12 - x ^ 3% y ^ 4 & lt; = 1e16 - x ^ 4% These are simple expressions to solve. Y = roof ((1e12 - x ^ 3). ^ (1/3)): floor ((1e16 - x ^ 4). ^ 0.25); N = numel (y); If n & gt; 0xy {x + 1} = [rep (x, 1, n); Y]; End end% cell array xy = cell2mat (xy) plane; Toc
The time required was ...
The time elapsed is 0.600419 seconds
for 100020001 combinations We tested, how many solutions did we find?
Size (xy) ans = 2 4371264
Of course, writing a whole search is easy.
tick [x, y] = meshgrid (0: 10000); K = (x ^ 3 + y ^ 3> gt1 = 1a 12) & amp; (X.4 + y. ^ 4 & lt; = 1e16); Xy = [x (k), y (k)]; Toc
I participated with 8 gigs of RAM on a 64 bit machine. But still this test was the CPU hog.
The time passed is 50.182385 seconds.
Note that due to moving point ideas, sometimes different points have to be met, depending on how the computation is done.
Finally, if your barrier equation is more complex, you may need to use roots in expression for constraints, to help find out where the obstacles are, good point here. Works for a more complex polynomial boundary.
Comments
Post a Comment