Skip to content

Instantly share code, notes, and snippets.

@fronx
Forked from moink/transclose.m
Created October 25, 2011 22:05
Show Gist options
  • Select an option

  • Save fronx/1314504 to your computer and use it in GitHub Desktop.

Select an option

Save fronx/1314504 to your computer and use it in GitHub Desktop.

Revisions

  1. fronx revised this gist Oct 25, 2011. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions transclose.m
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,14 @@
    %divides(3,1)=1 %Add [4 2] to the relation
    %divides(6,5)=1 %Add [27 9] to the relation
    %
    %divides=[
    % 0 0 0 0 0 0
    % 0 0 0 0 0 0
    % 1 0 0 0 0 0
    % 0 0 1 0 0 0
    % 0 1 0 0 0 0
    % 0 0 0 0 1 0];
    %
    %transdiv=transclose(divides);
    %%this returns the matrix
    % transdiv=[
  2. fronx revised this gist Oct 25, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions transclose.m
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    function A=transclose(A)
    %returns the transitive closure matrix of the input matrix
    %input: A(i,j) is 1 if the binary relation if (element i) R (element j) using the %notation in the introduction
    %of http://en.wikipedia.org/wiki/Transitive_closure
    %input: A(i,j) is 1 if the binary relation if (element i) R (element j) using the
    %notation in the introduction of http://en.wikipedia.org/wiki/Transitive_closure
    %
    %Usage example: Implements the first example problem on https://www.4clojure.com/problem/84
    %
  3. @invalid-email-address Anonymous created this gist Oct 25, 2011.
    33 changes: 33 additions & 0 deletions transclose.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    function A=transclose(A)
    %returns the transitive closure matrix of the input matrix
    %input: A(i,j) is 1 if the binary relation if (element i) R (element j) using the %notation in the introduction
    %of http://en.wikipedia.org/wiki/Transitive_closure
    %
    %Usage example: Implements the first example problem on https://www.4clojure.com/problem/84
    %
    %divideskey=[2 3 4 8 9 27];
    %%I don't actually use that variable, but it keeps track of what my matrix means
    %
    %divides=zeros(6)
    %
    %divides(4,3)=1 %Add [8,4] to the relation
    %divides(5,2)=1 %Add [9 3] to the relation
    %divides(3,1)=1 %Add [4 2] to the relation
    %divides(6,5)=1 %Add [27 9] to the relation
    %
    %transdiv=transclose(divides);
    %%this returns the matrix
    % transdiv=[
    % 0 0 0 0 0 0
    % 0 0 0 0 0 0
    % 1 0 0 0 0 0
    % 1 0 1 0 0 0
    % 0 1 0 0 0 0
    % 0 1 0 0 1 0];

    for i = 1:size(A,1)
    for j = 1:size(A,2)
    t=(A(i,j)==1 & A(j,:)==1);
    A(i,t)=1;
    end
    end