Location: Peripheral airways matlab/CellML @ 30e6db7fb82a / Peripheral_matlab_dell_updated / generalised_model / createSymmTMatrix.m

Author:
aram148 <42922407+aram148@users.noreply.github.com>
Date:
2022-07-26 11:49:42+12:00
Desc:
updated documentation and renamed model
Permanent Source URI:
https://models.fieldml.org/workspace/7e5/rawfile/30e6db7fb82a9bb715b0121cdfc131c19e5cb2ff/Peripheral_matlab_dell_updated/generalised_model/createSymmTMatrix.m

% A function that will compute the necessary transformation matrix, T,
% that maps all 

% This function will be structured as a recursive function, with the base
% case being the trivial 3-branch case (order 2)

% DATE: 22/02/17
% AUTHOR: Austin Ibarra
% VERSION: 1.0

% == LOG CHANGE == %

function T = createSymmTMatrix(order)
%% Initialise the matrix
numBr = 2^order - 1;
numRows = (numBr - 1)/2;
numCols = (numBr + 1)/2;
V = zeros(numRows,numCols);

%% Perform the looping
numElem = 2;  % Start off with 1/2, when filling out the matrix
count = 0;
row = 1;   % The current row that we are on
i = 1;
while i <= numCols   % loop along the columns

    V(row,i) = 1/numElem;
    count = count + 1;
        
    if i == numCols   
        % Check if we have reached the end of the matrix columns. If yes,
        % then check if we are on the last row, and if we are, then
        % terminate the loop.
        if row == numRows
            break
        else
            % Otherwise, it means that we need to move onto the next row,
            % reset count, and double numElem.
            row = row + 1;
            count = 0;
            i = 1;
            numElem = numElem*2;
        end
    else
        i = i + 1;
    end
    
    if count == numElem
        row = row + 1;   % Move onto the next row
        count = 0;      % Reset count back to zero
    end

end
%% Now, concatenate the matrices together to form T
I = eye((numBr + 1)/2);
ZERO = zeros(numBr,(numBr - 1)/2);
T = cat(2,cat(1,I,V),ZERO);
end