Вы находитесь на странице: 1из 4

Modeling System Influence with MATLAB

Derek Fermaint
Technical Report - Honors, Linear Algebra
April 24, 2016

MODELING SYSTEM INFLUENCE WITH MATLAB


Overview:
This program simulates the influence within systems. Each
node pathway on the system is either a 1 or -1 and the program
will run until either all of the 1 node pathways have influenced
the -1 node pathways to convert, or until all of the -1 nodes have
converted the 1’s. It was written to simulate the scenario of a
virus in a system, and therefore the user must input arbitrary
values of “infection” or “cure” chances. After the system has been
represented as a matrix, it will begin by initially infecting the
nodes at random. From there, it will begin to take turns of
cure/infection chances until the entire system is either cured or
destroyed.
Input:
System as a matrix, 4 parameters: infection chance (in
percent), cure chance (in percent), number of columns, number of
rows.

Output:
Display of final state of system, number of trials until
system became uniform (all 1’s or all -1’s).

Comments / Improvements:
There are several improvements I’d like to make in the future.
Such as converting the system into matrix form automatically, being
able to determine node infection/cure chances by using statistical
data instead of arbitrary in nature, and being able to analyze
multiple system styles to study natural phenomenon.

A question I would like to take further is: what factors come into
play that make a system robust? What can we incorporate into
systems that can prevent system collapse?

Fermaint 1
Modeling System Influence with MATLAB

Example run:

Source Code:

% parameters for user to enter


A = [ 0, 1, 1, 0; 1, 0, 1, 1; 1, 1, 0, 1; 0, 1, 1, 0;];
infectionChance = 0.60;
cureChance = .30;
firstColumn = 1;
lastColumn = 4;

% declares variables for the system


numOfPathways = 0;
infectedPathway = 0;
curedPathway = 0;
uniformSystem = false;
counter = 0;

% counts number of nodes on the system


for i = firstColumn:lastColumn
for j = firstColumn:lastColumn
if A(i,j) == 1

Fermaint 2
Modeling System Influence with MATLAB

numOfPathways = numOfPathways + 1;
end
end
end

% displays relevant values


disp(['Original system: ']);
disp(A);

% first iteration to set up system randomly with disease


for i = firstColumn:lastColumn
diceRoll = rand;
if diceRoll < infectionChance
for j = firstColumn:lastColumn
A(i,j) = -1*A(i,j);
end
end
end
disp(['Initial randomly infected system: ']);
disp(A);

% loops sequential steps until entire system is either


% entirely infected or entirely cured

while uniformSystem == false


% program core
for m = firstColumn:lastColumn
for n = firstColumn:lastColumn
if A(m,n) == -1
% if selected node is -1
% turn, chance to cure
diceRoll = rand;
if diceRoll < cureChance
A(m,n) = 1;
% if fails to cure, rolls to see if
% infection will spread to neighboring nodes
else
diceRoll = rand;
if diceRoll < infectionChance
for g = firstColumn:lastColumn
A(n,g) = -1*A(n,g);
end
end
end
end
end
end

Fermaint 3
Modeling System Influence with MATLAB

% checks for system uniformity


for i = firstColumn:lastColumn
for j = firstColumn:lastColumn
if A(i,j) == 1
curedPathway = curedPathway + 1;
elseif A(i,j) == -1
infectedPathway = infectedPathway + 1;
end
end
end
if curedPathway == numOfPathways || infectedPathway ==
numOfPathways
uniformSystem = true;
else
curedPathway = 0;
infectedPathway = 0;
uniformSystem = false;
end
counter = counter + 1;
end

disp(['Program required ', num2str(counter), ' trials to


complete.']);
disp(['Final state of system: ']);
disp(A);

Fermaint 4

Вам также может понравиться