poster
2019-12-10, 20:48
关于{x,y} ,我有一些不等式,它满足以下方程式:
x>=0 y>=0 f(x,y)=x^2+y^2>=100 g(x,y)=x^2+y^2=100 and x^2+y^2= 1e12 x^4 + y^4 = 0, y >= 0 解决该系统的所有整数解。请注意,此处以ANY形式进行整数编程是不够的,因为需要所有整数解。
在这里使用meshgrid将迫使我们查看域(0:10000)X(0:10000)中的点。因此,这将迫使我们对一组1e8点进行采样,测试每个点以查看它们是否满足约束条件。
尽管仍然需要一些努力,但简单的循环可能比这更有效。
% Note that I will store these in a cell array, % since I cannot preallocate the results. tic xmax = 10000; xy = cell(1,xmax); for x = 0:xmax % solve for y, given x. This requires us to % solve for those values of y such that % y^3 >= 1e12 - x.^3 % y^4 0 xy{x+1} = [repmat(x,1,n);y]; end end % flatten the cell array xy = cell2mat(xy); toc 所需时间是...
Elapsed time is 0.600419 seconds. 在我们可能测试过的100020001个组合中,找到了多少个解决方案?
size(xy) ans = 2 4371264 诚然,穷举搜索更容易编写。
tic [x,y] = meshgrid(0:10000); k = (x.^3 + y.^3 >= 1e12) & (x.^4 + y.^4
x>=0 y>=0 f(x,y)=x^2+y^2>=100 g(x,y)=x^2+y^2=100 and x^2+y^2= 1e12 x^4 + y^4 = 0, y >= 0 解决该系统的所有整数解。请注意,此处以ANY形式进行整数编程是不够的,因为需要所有整数解。
在这里使用meshgrid将迫使我们查看域(0:10000)X(0:10000)中的点。因此,这将迫使我们对一组1e8点进行采样,测试每个点以查看它们是否满足约束条件。
尽管仍然需要一些努力,但简单的循环可能比这更有效。
% Note that I will store these in a cell array, % since I cannot preallocate the results. tic xmax = 10000; xy = cell(1,xmax); for x = 0:xmax % solve for y, given x. This requires us to % solve for those values of y such that % y^3 >= 1e12 - x.^3 % y^4 0 xy{x+1} = [repmat(x,1,n);y]; end end % flatten the cell array xy = cell2mat(xy); toc 所需时间是...
Elapsed time is 0.600419 seconds. 在我们可能测试过的100020001个组合中,找到了多少个解决方案?
size(xy) ans = 2 4371264 诚然,穷举搜索更容易编写。
tic [x,y] = meshgrid(0:10000); k = (x.^3 + y.^3 >= 1e12) & (x.^4 + y.^4