Download code

Jump to: navigation, search

Back to Combinatorial_Geometry_in_MATLAB

Download for Windows: zip

Download for UNIX: zip, tar.gz, tar.bz2

mimafun

function y=mimafun(x,a,b) 
%a,b = columns 
V=a+b*x; 
V(:,2)=-V; 
y=sum(max(V));


Arrangement_of_lines.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Combinatorial_Geometry_in_MATLAB?oldid=9556
14 
15 
16 n = 5; 
17 a = rand(n,1); 
18 b = rand(n,1); 
19 f_crit = @(X) max(a+X*b) - min(a+X*b); 
20 F_crit = @(X) max(repmat(a,1,length(X))+repmat(X',length(a), 1).*repmat(b,1,length(X))) - ...
21               min(repmat(a,1,length(X))+ repmat(X',length(a),1).*repmat(b,1,length(X))); 
22 
23 
24 crossings = -(repmat(a,1,n)-repmat(a',n,1))./(repmat(b,1,n)-repmat(b',n,1)); 
25 triu_id   = cumsum(eye(n),2)-eye(n); 
26 crossings = sort(crossings(logical(triu_id))); 
27 crossingy = F_crit(crossings)'; 
28 [Y,idX]   = min(crossingy); 
29 X         = crossings(idX); 
30 
31 domainx = [min(crossings), max(crossings)]; 
32 domainy = [a+b*domainx(1), a+b*domainx(2)]; 
33 miax = [min(domainy(:)), max(domainy(:))]'; 
34 allx = [repmat(crossings,1,2), repmat(nan,length(crossings),1)]'; 
35 ally = repmat([miax; NaN],1,length(crossings)); 
36 
37 figure('color', [1 1 1]); 
38 a1=subplot(2,1,1); 
39 plot(domainx, domainy, 'linewidth',2); 
40 hold on 
41 plot(allx(:),ally(:),':k'); 
42 hold off 
43 title('All lines'); 
44 a2=subplot(2,1,2); 
45 plot(crossings,crossingy,'-', 'linewidth',2); 
46 hold on 
47 plot(X, Y, 'or', 'Markerfacecolor', [1 0 0]); 
48 plot(crossings,crossingy,'.k'); 
49 hold off 
50 text(X,Y,sprintf('  X=%5.2f, Y=%5.2f', X, Y), 'rotation', 90) 
51 title('Minimum'); 
52 linkaxes([a1,a2],'x');


hijacker
hijacker
hijacker
hijacker