text:
function GCO_LoadLib()
% GCO_LoadLib    Attempt to load the GCO_MATLAB library.
%    GCO_LoadLib is used internally by all other GCO_MATLAB commands
%    to compile (if necessary), load, and bind the wrapper library.

if (isempty(getenv('GCO_MATLAB')))
	GCO_BuildLib(struct('Force',false));
	if (exist('gco_matlab') ~= 3)
	    error('Failed to load gco_matlab library');
	end
	warning on GCO:int32;
	setenv('GCO_MATLAB','LOADED'); % environment variables 10x faster than 'exists'
end

end

author: andrewssobral

repo: lrslibrary


text:
function t = fractile(x, f)
%FRACTILE finds fractiles of a distribution
%   T = FRACTILE(X, F) finds a value T for which a fraction F of the
%   elements of X are less than T. A fractile is like a centile, except
%   that the argument is a fraction rather then a percentage.
%
%   Linear interpolation is used between data points. The minimum and
%   maximum values in X are returned for F=0 and F=1 respectively. F may be
%   a matrix; the result is the corresponding matrix of fractiles.

% Note on the algorithm:
% Forming a histogram seems to take as long as SORT, but sort is much
% simpler, since histogramming always needs to be used recursively to work
% with uneven distributions. However, for very large amounts of data it may
% be worthwhile to look at providing a recursive histogram method.

validateattributes(x, {'numeric'}, {});
validateattributes(f, {'numeric'}, {'>=' 0 '<=' 1});

x = sort(x(:));
n = numel(x);
fn = n * f(:);      % the ideal index into sorted g

i = floor(fn + 0.5);        % index of value just less than f

ga = x(max(i, 1));
gb = x(min(i+1, n));

r = fn + 0.5 - i;
t = (1-r) .* ga + r .* gb;    % interpolate

t = reshape(t, size(f));

end

author: cerr

repo: CERR

save_path: github-repos/MATLAB/cerr-CERR


text:
classdef marrmotBMI_oct < handle
    % MARRMoT m01 implemented as a BMI model

    properties
        % BMI required
        startTime           % start time
        endTime             % end time
        dt                  % time step size
        time_unit           % units of time
        time = 1;           % current time step
        lat                 % latitude
        lon                 % longitude

        % Indepdendent of model
        forcing = struct('precip',0,...             % time series of precipitation
                         'temp',0,...               % time series of temperature
                         'pet',0,...                % time series of potential evapotranspiration
                         'delta_t',0,...            % time step size in [days]
                         'time_unit','str');        % string with time units
        solver = struct('name','str',...            % string with solver function name
                        'resnorm_tolerance',0,...   % approximation accuracy
                        'resnorm_maxiter',0);       % max number of re-runs

            % Output storage for a single time-step
            output_externalFluxes = struct('Q',0,...    % Streamflow
                                           'Ea',0);     % Actual evap
            output_internalFluxes = struct('tmp',0);    % Internal fluxes, will be appended later
            output_modelStorages  = struct('S1',0);     % Model stores, can be appended later
            output_waterBalance   = 0;                  % Can be an optional argument to return a water balance check

        % Dependent on the model
        model_name          % name of the model function file
        parameters          % parameter values from some source
        store_num           % number of stores
        path                % location of config file
        store_cur           % vector with current model states
    end

    %the following is the heart of the BMI class. Every BMI model needs to
    %implement these methods. For some methods a standard implementation is
    %provided (example: update_until). These can be overwritten by
    %implementing them in the model class file. See the AR1class.m for an
    %example. Methods that are not implemented will throw an error msg
    %declaring they are not implemented.
    %See the BMI reference for more details.
    methods

        % Unsure whether this is still needed - check
%         function obj=m01BMI()
%         end

%% Model control functions

        % Initialize the model: this (1) loads data, (2) selects the model,
        % (3) sets all the settings needed to run the model; all from a
        % single _model-specific_ config file.
        function  initialize(obj,path)
            % Load config file
            load(path)                          % contains everything needed to run the model, plus BMI stuff

            % Assign values to object
            obj.model_name = model_name;
            obj.startTime  = time_start;
            obj.endTime    = time_end;
            obj.dt         = forcing.delta_t_days;
            obj.time_unit  = forcing.time_unit;
            obj.forcing    = forcing;
            obj.solver     = solver;
            obj.parameters = parameters;
            obj.store_cur  = store_ini;         % this value gets updated on every update() call
            obj.store_num  = length(store_ini);
            obj.path       = path;
            obj.lat        = data_origin(1);
            obj.lon        = data_origin(2);
        end

        % Run model for 1 time step
        function update(obj)

           % Get the forcing for this time step
            input_forcing.precip       = obj.forcing.precip(obj.time);
            input_forcing.temp         = obj.forcing.temp(obj.time);
            input_forcing.pet          = obj.forcing.pet(obj.time);
            input_forcing.delta_t      = obj.forcing.delta_t_days;

           % Run model for 1 time step
            [output_ex,...                                                  % Fluxes leaving the model: simulated flow (Q) and evaporation (Ea)
             output_in,...                                                  % Internal model fluxes
             output_ss,...                                                  % Internal storages
             ] = ...                                                        % Water balance check
                                feval(obj.model_name,...                    % Model function name
                                      input_forcing,...                     % Time series of climatic fluxes in simulation period
                                      obj.store_cur,...                     % Initial storages
                                      obj.parameters,...                    % Parameter values
                                      obj.solver);                          % Solver settings

            % Update variables
            obj.store_cur             = structfun(@mean,output_ss);         % ugly hack to get the current storages out of the structure, but works in octave
            obj.output_externalFluxes = output_ex;
            obj.output_internalFluxes = output_in;
            obj.output_modelStorages  = output_ss;
%            obj.output_waterBalance   = output_wb;
            obj.time                  = obj.time + obj.dt;
        end

        % Function to continously run the model
        function update_until(obj,until_time)
            while (obj.time <= until_time)
                obj.update;
            end
        end

        % Finalize (empty)
        function finalize()
        end

%% Variable getter and setter

        % Get current values
        function output = get_value(obj,long_var_name)
            switch long_var_name
                case 'P'
                    output = obj.forcing.precip;
                case 'T'
                    output = obj.forcing.temp;
                case 'Ep'
                    output = obj.forcing.pet;
                case 'S(t)'
                    output = obj.store_cur;
                case 'mod'
                    output = obj.model_name;
                case 'par'
                    output = obj.parameters;
                case 'sol'
                    output = obj.solver;
                case 'flux_out'
                    output = obj.output_externalFluxes;
                case 'flux_in'
                    output = obj.output_internalFluxes;
                case 'wb'
                    output = obj.output_waterBalance;
                otherwise
                    error('unkown variable');
            end
        end

        function output = get_value_at_indices(obj,long_var_name, inds)
            if inds ~= [0,0]
                error(['Indices out of bounds.']);
            else
                output = get_value(obj,long_var_name);
            end
        end

        % Set inputs using handles
        function set_value(obj,long_var_name, src)
            switch long_var_name
                case 'P'
                    obj.forcing.precip = src;
                case 'T'
                    obj.forcing.temp = src;
                case 'Ep'
                    obj.forcing.pet = src;
                case 'S(t)'
                    obj.store_cur = src;
                case 'mod'
                    obj.model_name = src;
                case 'par'
                    obj.parameters = src;
                case 'sol'
                    obj.solver = src;
                case 'flux_out'
                    obj.output_externalFluxes = src;
                case 'flux_in'
                    obj.output_internalFluxes = src;
                case 'wb'
                    obj.output_waterBalance = src;
                otherwise
                    error('unkown variable');
            end
        end

        function set_value_at_indices(obj,long_var_name, inds, src)
            if inds ~= [0,0]
                error(['Indices out of bounds.']);
            else
                set_value(obj,long_var_name, src);
            end
        end

%% Model information functions

        % Get input variable names
        function output = get_input_var_names(obj)
            output={'Precipitation time series > P',...
                    'Temperature time series > T',...
                    'Potential evapotranspiration time series > Ep',...
                    'Storages (time = t) > S(t)',...
                    'Model function name > mod',...
                    'Parameters > par',...
                    'Solver > sol'};
        end

        % Get output variable names
        function output = get_output_var_names(obj)
            output={'Fluxes leaving the model > flux_out',...
                    'Internal fluxes > flux_in',...
                    'Storages (time = t) > S(t)',...
                    'Water balance check > wb'};
        end

        % Model components
        function output = get_component_name(obj)
            output=['BMI implemented for MARRMoT models, currently running ',obj.model_name];
        end

%% Time functions

        % Start time
        function output = get_start_time(obj)
            # datenum returns the date as a serial number since Jan 1 0000
            # output will return the date as a number of days since CUT - 1 Jan 1970
            CUT_time = [1970 01 01 0 0 0];
            output = datenum(obj.startTime) - datenum(CUT_time);
            # output = datenum(obj.startTime);
        end

        % End time
        function output = get_end_time(obj)
            # output will return the date as a number of days since CUT - 1 Jan 1970
            CUT_time = [1970 01 01 0 0 0];
            output = datenum(obj.endTime) - datenum(CUT_time);
        end

        % Time units
        function output = get_time_units(obj)
            timeformat_index = strncmp(obj.time_unit, 'days', 3);
            if timeformat_index ~= 0
              commandstring = "days since 1970-01-01 00:00:00.0 00:00";
              output = commandstring;
            else
              output = obj.time_unit;
            end
        end

        % Current time
        function output = get_current_time(obj)
            CUT_time = [1970 01 01 0 0 0];
            t_current = obj.time + datenum(obj.startTime)- datenum(CUT_time) - 1;
            output = t_current;
        end

        % Time step
        function output = get_time_step(obj)
            output=obj.dt;
        end

%% Model grid

        % Grid type
        function output = get_grid_type(~)
            output = 'uniform_rectilinear';         % Fixed for all MARRMoT models
        end

        % Grid rank
        function output = get_grid_rank(~)
            output = 2;                             % Fixed for all MARRMoT models
        end

        % Grid size
        function output = get_grid_size(~)
            output = 1;                             % Fixed for all MARRMoT models
        end

        % Grid shape
        function output = get_grid_shape(~)
            output = [1,1];                         % Fixed for all MARRMoT models
        end

        % Grid origin
        function output = get_grid_origin(obj)
            output = [obj.lat,obj.lon];
        end

        % Grid spacing
        function output = get_grid_spacing(~)
            output = [0,0];                         % Fixed for all MARRMoT models
        end

        % Grid X
        function output = get_grid_x(~)
            output = 1;                              % Fixed for all MARRMoT models
        end

        % Grid Y
        function output = get_grid_y(~)
            output = 1;                              % Fixed for all MARRMoT models
        end

        % Grid Z
        function output = get_grid_z(~)
            output = 1;                              % Fixed for all MARRMoT models
        end

%% Variable information

        % Units
        function output = get_var_units(obj,long_var_name)
            switch long_var_name
                case 'P'
                    output = ['mm ',obj.time_unit];
                case 'T'
                    output = 'degree C';
                case 'Ep'
                    output = ['mm ',obj.time_unit];
                case 'S(t)'
                    output = 'mm';
                case 'mod'
                    output = '-';
                case 'par'
                    output = 'see model documentation';
                case 'sol'
                    output = '-';
                case 'flux_out'
                    output = ['mm ',obj.time_unit];
                case 'flux_in'
                    output = ['mm ',obj.time_unit];
                case 'wb'
                    output = 'mm';
                otherwise
                    error('unkown variable. please use one of the following variables: P, T, Ep, S, mod, par, sol, f;ux_out, flux_in, wb');
            end
        end

        % Type
        function output = get_var_type(obj,long_var_name)
            switch long_var_name
                case 'P'
                    tmp = obj.forcing.precip;
                    tmp = whos('tmp');
                    output = tmp.class;
                case 'T'
                    tmp = obj.forcing.temp;
                    tmp = whos('tmp');
                    output = tmp.class;
                case 'Ep'
                    tmp = obj.forcing.pet;
                    tmp = whos('tmp');
                    output = tmp.class;
                case 'S(t)'
                    tmp = obj.store_cur;
                    tmp = whos('tmp');
                    output = tmp.class;
                case 'mod'
                    tmp = obj.model_name;
                    tmp = whos('tmp');
                    output = tmp.class;
                case 'par'
                    tmp = obj.parameters;
                    tmp = whos('tmp');
                    output = tmp.class;
                case 'sol'
                    tmp = obj.solver;
                    tmp = whos('tmp');
                    output = tmp.class;
                case 'flux_out'
                    tmp = obj.output_externalFluxes;
                    tmp = whos('tmp');
                    output = tmp.class;
                case 'flux_in'
                    tmp = obj.output_internalFluxes;
                    tmp = whos('tmp');
                    output = tmp.class;
                case 'wb'
                    tmp = obj.output_waterBalance;
                    tmp = whos('tmp');
                    output = tmp.class;
                otherwise
                    error('unkown variable');
            end
        end

        % Item size
        function output = get_var_itemsize(obj,long_var_name)
            switch long_var_name
                case 'P'
                    tmp = obj.forcing.precip;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                case 'T'
                    tmp = obj.forcing.temp;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                case 'Ep'
                    tmp = obj.forcing.pet;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                case 'S(t)'
                    tmp = obj.store_cur;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                case 'mod'
                    tmp = obj.model_name;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                case 'par'
                    tmp = obj.parameters;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                case 'sol'
                    tmp = obj.solver;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                case 'flux_out'
                    tmp = obj.output_externalFluxes;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                case 'flux_in'
                    tmp = obj.output_internalFluxes;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                case 'wb'
                    tmp = obj.output_waterBalance;
                    tmp = whos('tmp');
                    output = tmp.bytes/(tmp.size(1)*tmp.size(2));
                otherwise
                    error('unkown variable');
            end
        end

        % Item nbytes
        function output = get_var_nbytes(obj,long_var_name)
            switch long_var_name
                case 'P'
                    tmp = obj.forcing.precip;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                case 'T'
                    tmp = obj.forcing.temp;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                case 'Ep'
                    tmp = obj.forcing.pet;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                case 'S(t)'
                    tmp = obj.store_cur;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                case 'mod'
                    tmp = obj.model_name;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                case 'par'
                    tmp = obj.parameters;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                case 'sol'
                    tmp = obj.solver;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                case 'flux_out'
                    tmp = obj.output_externalFluxes;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                case 'flux_in'
                    tmp = obj.output_internalFluxes;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                case 'wb'
                    tmp = obj.output_waterBalance;
                    tmp = whos('tmp');
                    output = tmp.bytes;
                otherwise
                    error('unkown variable');
            end
        end

        % Grid
        function output = get_var_grid(obj,long_var_name)
            output = 1;                 % Grid size is 1 for all models, so arbitrary values
        end

        % Location
        function output = get_var_location(obj,long_var_name)
            output = 'face';            % Grid size is 1 for all models, so arbitrary values
        end

    end
end

author: wknoben

repo: MARRMoT

save_path: github-repos/MATLAB/wknoben-MARRMoT


text:
function [vertex,faces] = compute_saddle_points(Q,D,mask)

% compute_saddle_points - compute saddle points of a Voronoi segmentation
%
%   [vertex,faces] = compute_saddle_points(Q,D[,mask]);
%
%   Q is a voronoi index map.
%   D is the distance function associated to the voronoi map.
%
%   The vertex of the saddle points are first the double points (meeting
%   points of the voronoi diagram along the boundary of the domain) and
%   then the triple points (meeting points of 3 cells).
%
%   Copyright (c) 2008 Gabriel Peyre

if nargin==3 && not(isempty(mask))
    Q(mask==0) = -1;
end

Q1 = zeros(size(Q)+2)-1;
Q1(2:end-1,2:end-1) = Q;
V = [];
v = Q1(1:end-1,1:end-1); V = [V v(:)];
v = Q1(2:end,1:end-1); V = [V v(:)];
v = Q1(1:end-1,2:end); V = [V v(:)];
v = Q1(2:end,2:end); V = [V v(:)];
V = sort(V,2);
d = (V(:,1)~=V(:,2)) + (V(:,2)~=V(:,3)) + (V(:,3)~=V(:,4));
V = V';

I = find(d>=2);

[vx,vy] = ind2sub(size(Q)+1, I);
vx = clamp(vx,1,size(Q,1));
vy = clamp(vy,1,size(Q,1));
J = vx+(vy-1)*size(Q,1);

% sort according to distance
[tmp,s] = sort(D(J), 1, 'descend');
I = I(s);

[vx,vy] = ind2sub(size(Q)+1, I);
vx = clamp(vx,1,size(Q,1));
vy = clamp(vy,1,size(Q,1));
vertex = cat(1,vx',vy');

V = sort(V, 1, 'descend');
faces = V(1:3, I);

if isempty(vertex)
    % add farthest point
    [tmp,I] = max( D(:) );
    [vx,vy] = ind2sub(size(D), I(1));
    vertex = [vx;vy];
    faces = [-1 -1 -1]';
end

I = find( faces(1,:)<0 | faces(2,:)<0 | faces(3,:)<0 );
J = find( faces(1,:)>0 & faces(2,:)>0 & faces(3,:)>0 );
faces = cat(2, faces(:,I), faces(:,J) );

author: alecjacobson

repo: gptoolbox


text:
%run this test case with the command
%results = runtests('fillGapsSmallTests.m')
function tests = fillGapsSmallTests
tests = functiontests(localfunctions);
end

function testSmallGlpk(testCase)
%Test using small model
sourceDir = fileparts(which(mfilename));
load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
modelDB=model; % Keep as database with reactions
try
    oldSolver=getpref('RAVEN','solver');
catch
end
setRavenSolver('glpk');

%Remove first 10 reactions
model=removeReactions(modelDB,(1:10));
modelDB.id='DB';
try
    evalc('[newConnected,cannotConnect,addedRxns,model,exitFlag]=fillGaps(model,modelDB)');
catch
    try
        setRavenSolver(oldSolver);
    catch
        rmpref('RAVEN','solver');
    end
    error('Solver not working')
end
sol=solveLP(model);
try
    setRavenSolver(oldSolver);
catch
    rmpref('RAVEN','solver');
end
%Should give non-zero flux
verifyTrue(testCase,-sol.f>0);
end

function testSmallGurobi(testCase)
if exist('gurobi','file')~=3
    error('Gurobi not installed or cannot be found in MATLAB path, test skipped')
end
%Test using small model
sourceDir = fileparts(which(mfilename));
load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
modelDB=model; % Keep as database with reactions
try
    oldSolver=getpref('RAVEN','solver');
catch
end
setRavenSolver('gurobi');

%Remove first 10 reactions
model=removeReactions(modelDB,(1:10));

modelDB.id='DB';
try
    evalc('[newConnected,cannotConnect,addedRxns,model,exitFlag]=fillGaps(model,modelDB)');
catch
    try
        setRavenSolver(oldSolver);
    catch
        rmpref('RAVEN','solver');
    end
    error('Solver not working')
end
sol=solveLP(model);
try
    setRavenSolver(oldSolver);
catch
    rmpref('RAVEN','solver');
end
%Expect at least 5% of the original growth
verifyTrue(testCase,-sol.f>0);
end

function testSmallCobra(testCase)
if exist('initCobraToolbox.m','file')~=2
    error('COBRA Toolbox not installed or cannot be found in MATLAB path, test skipped')
end
%Test using small model
sourceDir = fileparts(which(mfilename));
load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
modelDB=model; % Keep as database with reactions
try
    oldSolver=getpref('RAVEN','solver');
catch
end
setRavenSolver('cobra');

%Remove first 10 reactions
model=removeReactions(modelDB,(1:10));
modelDB.id='DB';
try
    evalc('[newConnected,cannotConnect,addedRxns,model,exitFlag]=fillGaps(model,modelDB)');
catch
    try
        setRavenSolver(oldSolver);
    catch
        rmpref('RAVEN','solver');
    end
    error('Solver not working')
end
sol=solveLP(model);
try
    setRavenSolver(oldSolver);
catch
    rmpref('RAVEN','solver');
end
%Expect at least 5% of the original growth
verifyTrue(testCase,-sol.f>0);
end

author: SysBioChalmers

repo: RAVEN


text:
function [ x, seed ] = r8vec_uniform_01 ( n, seed )

%*****************************************************************************80
%
%% R8VEC_UNIFORM_01 returns a unit pseudorandom R8VEC.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    21 September 2006
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Paul Bratley, Bennett Fox, Linus Schrage,
%    A Guide to Simulation,
%    Second Edition,
%    Springer, 1987,
%    ISBN: 0387964673,
%    LC: QA76.9.C65.B73.
%
%    Bennett Fox,
%    Algorithm 647:
%    Implementation and Relative Efficiency of Quasirandom
%    Sequence Generators,
%    ACM Transactions on Mathematical Software,
%    Volume 12, Number 4, December 1986, pages 362-376.
%
%    Pierre L'Ecuyer,
%    Random Number Generation,
%    in Handbook of Simulation,
%    edited by Jerry Banks,
%    Wiley, 1998,
%    ISBN: 0471134031,
%    LC: T57.62.H37.
%
%    Peter Lewis, Allen Goodman, James Miller,
%    A Pseudo-Random Number Generator for the System/360,
%    IBM Systems Journal,
%    Volume 8, Number 2, 1969, pages 136-143.
%
%  Parameters:
%
%    Input, integer N, the number of entries in the vector.
%
%    Input, integer SEED, a seed for the random number generator.
%
%    Output, real X(N,1), the vector of pseudorandom values.
%
%    Output, integer SEED, an updated seed for the random number generator.
%
  x = zeros ( n, 1 );

  i4_huge = 2147483647;

  if ( seed == 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'R8VEC_UNIFORM_01 - Fatal error!\n' );
    fprintf ( 1, '  Input SEED = 0!\n' );
    error ( 'R8VEC_UNIFORM_01 - Fatal error!' );
  end

  r = zeros ( n, 1 );

  for i = 1 : n

    k = floor ( seed / 127773 );

    seed = 16807 * ( seed - k * 127773 ) - k * 2836;

    if ( seed < 0 )
      seed = seed + i4_huge;
    end

    x(i) = seed * 4.656612875E-10;

  end

  return
end

author: johannesgerer

repo: jburkardt-m


text:
function [A,B,D,E,I]=E7x(R,C)
% Subprogram for 7th order Elliptical LPF
N=7;U=11;M=1;Y=11;
% create space for and zero A1 & B2 matrices
A1=zeros(U+N);B2=zeros(U+N,N+M);
%
% R=[R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15]
%    1  2  3  4  5  6  7  8  9  10  11  12  13  14  15
%
% C = [C1 C2 C3 C4 C5 C6 C7];
%      1  2  3  4  5  6  7
%
% For column alignment:
%
% V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11   iC1 iC2 iC3 iC4 iC5 iC6 iC7
% 1  2  3  4  5  6  7  8  9  10  11    12  13  14  15  16  17  18
%
% Create A1
%
%       -V1/R2      +iC1
A1(1,1)=-1/R(2);A1(1,12)=1; % -Ein/R1 - V1/R2 + iC1 = 0
%
G2=1/R(3)+1/R(5); % For row 2 below
%   +V1/R3        -V2*G2       +iC2
A1(2,1)=1/R(3);A1(2,2)=-G2;A1(2,13)=1; % V1/R3 -V2*G2 + iC2 = 0
%
A1(3,3)=-1/R(6);A1(3,4)=1/R(6);A1(3,13)=-1;A1(3,14)=1; % -V3/R6 + V4/R6 - iC2 + iC3 = 0
%
G4=1/R(6)+1/R(9)+1/R(10); % For row 4 below
%
% V3/R6        +V6/R9        +V8/R10         -V4*G4       +iC4 = 0
A1(4,3)=1/R(6);A1(4,6)=1/R(9);A1(4,8)=1/R(10);A1(4,4)=-G4;A1(4,15)=1;
A1(5,1)=1/R(4);A1(5,5)=-1/R(4);A1(5,15)=-1;A1(5,14)=-1;
A1(6,5)=1/R(7);A1(6,6)=-1/R(7);A1(6,14)=-1;
A1(7,6)=1/R(8);A1(7,7)=-1/R(8);A1(7,17)=-1;A1(7,18)=-1;
A1(8,4)=1/R(10);A1(8,8)=-(1/R(10)+1/R(11));A1(8,16)=1;
A1(9,10)=1/R(12);A1(9,9)=-1/R(12);A1(9,17)=1;A1(9,16)=-1;
G10=1/R(12)+1/R(14)+1/R(15); % For row 10 below
A1(10,18)=1;A1(10,10)=-G10;A1(10,11)=1/R(14);A1(10,9)=1/R(12);
A1(11,7)=1/R(13);A1(11,11)=-1/R(13);A1(11,17)=-1;
A1(12,1)=-1; % 0-V1=E1
A1(13,3)=1;A1(13,2)=-1; % V3-V2=E2
A1(14,6)=1;A1(14,3)=-1; % V6-V3=E3
A1(15,5)=1;A1(15,4)=-1; % V5-V4=E4
A1(16,9)=1;A1(16,8)=-1; % V9-V8=E5
A1(17,11)=1;A1(17,9)=-1; % V11-V9=E6
A1(18,7)=1;A1(18,10)=-1; % V7-V10=E7
%
% B2
%
E1=1;E2=1;E3=1;E4=1;E5=1;E6=1;E7=1;Ein=1;
% E1 E2 E3 E4 E5 E6 E7 Ein  Source
% 1  2  3  4  5  6  7  8    Column of B2
%
B2(12,1)=E1;
B2(13,2)=E2;
B2(14,3)=E3;
B2(15,4)=E4;
B2(16,5)=E5;
B2(17,6)=E6;
B2(18,7)=E7;
B2(1,8)=Ein/R(1);

%
P=diag([C(1) C(2) C(3) C(4) C(5) C(6) C(7)]);
%
% Template "canned" statements
%
V=A1\B2;H=V(U+1:U+N,1:N+M);I=eye(N);
AB=P\H;A=AB(1:N,1:N);B=AB(1:N,N+1:N+M);
D=V(Y:Y,1:N);E=V(Y:Y,N+1:N+M);

author: Sable

repo: mcbench-benchmarks


text:
classdef prtPreProcFilter < prtPreProc
    % prtPreProcFilter   Data filtering
    %   Apply the filter specified in the propertes a and b to the rows of
    %   the data in dataSet.X:
    %
    % ds = prtDataGenCylinderBellFunnel;
    % b = fir1(21,.5);
    % pp = prtPreProcFilter('b',b,'a',1);
    % pp = pp.train(ds);
    % dsLpf = pp.run(ds);
    % subplot(1,2,1); imagesc(ds);
    % subplot(1,2,2); imagesc(dsLpf);

    properties (SetAccess=private)
        name = 'Filter'  % Zero Mean Unit Variance
        nameAbbreviation = 'Filt'  % ZMUV
    end

    properties
        b = [];
        a = 1;
        filtfilt = true;
    end

    methods
        function Obj = prtPreProcFilter(varargin)
            Obj = prtUtilAssignStringValuePairs(Obj,varargin{:});
        end
    end

    methods (Access=protected,Hidden=true)

        function self = trainAction(self,ds)
            % nothing to do
        end

        function ds = runAction(self,ds)
            % Remove the means and normalize the variance
            X = ds.X;
            if self.filtfilt
                X = filtfilt(self.b,self.a,X')';
            else
                X = filter(self.b,self.a,X')';
            end
            ds.X = X;
        end

        function xOut = runActionFast(self,xIn,ds) %#ok<INUSD>
           if self.filtfilt
                xOut = filtfilt(self.b,self.a,xIn')';
            else
                xOut = filter(self.b,self.a,xIn')';
            end
        end
    end

    methods (Hidden)

        function str = exportSimpleText(self) %#ok<MANU>
            error('Not implemented');
            %             titleText = sprintf('%% prtPreProcZmuv\n');
            %             zmuvMeansText = prtUtilMatrixToText(self.means,'varName','means');
            %             zmuvVarsText = prtUtilMatrixToText(self.stds,'varName','std');
            %             str = sprintf('%s%s%s',titleText,zmuvMeansText,zmuvVarsText);
        end
    end
end

author: covartech

repo: PRT

save_path: github-repos/MATLAB/covartech-PRT


text:
function [rtk,D,nb]=ddmat(rtk,D)

global glc
nf=rtk.NF; na=rtk.na;nb=0;
MAXSAT=glc.MAXSAT;

for i=1:MAXSAT
    for j=1:glc.NFREQ
        rtk.sat(i).fix(j)=0;
    end
end

for i=1:na
   D(i,i)=1;
end

for m=1:5
    nofix=(m==2&&rtk.opt.glomodear==0)||(m==4&&rtk.opt.bdsmodear==0);

    k=na;
    for f=1:nf

        for i=k+1:k+MAXSAT
            if rtk.x(i)==0||~test_sys(rtk.sat(i-k).sys,m)||...
                    ~rtk.sat(i-k).vsat(f)||~rtk.sat(i-k).half(f)
                continue;
            end
            if rtk.sat(i-k).lock(f)>0&&~bitand(rtk.sat(i-k).slip(f),2)&&...
                    rtk.sat(i-k).azel(2)>=rtk.opt.elmaskar&&~nofix
                rtk.sat(i-k).fix(f)=2;
                break;
            else
                rtk.sat(i-k).fix(f)=1;
            end
        end

        for j=k+1:k+MAXSAT
            if i==j||rtk.x(j)==0||~test_sys(rtk.sat(j-k).sys,m)||...
                    ~rtk.sat(j-k).vsat(f)
                continue;
            end
            if rtk.sat(j-k).lock(f)>0&&~bitand(rtk.sat(j-k).slip(f),2)&&...
                    rtk.sat(i-k).vsat(f)&&...
                    rtk.sat(j-k).azel(2)>=rtk.opt.elmaskar&&~nofix
                D(na+nb+1,i)= 1;
                D(na+nb+1,j)=-1;
                nb=nb+1;
                rtk.sat(j-k).fix(f)=2;
            else
                rtk.sat(j-k).fix(f)=1;
            end
        end

        k=k+MAXSAT;
    end

end

return

repo: GINav


text:
% BACKEND
%
% Files
%   CheckForJVM     - Throws an error if the JVM is not available.
%   SafeGetField    - A safe wrapper to GETFIELD.
%   SetDefaultValue - Initialise a missing or empty value in the caller.
%   strcontains     - Does a cell array contain a particular string?