Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs251_group07
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
KSHITIJ GARG
cs251_group07
Commits
b5f15891
Commit
b5f15891
authored
Aug 23, 2016
by
KSHITIJ GARG
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete backward_solve.m
parent
597279f1
Changes
1
Hide whitespace changes
Inline
Sidebyside
Showing
1 changed file
with
0 additions
and
57 deletions
+0
57
backward_solve.m
backward_solve.m
+0
57
No files found.
backward_solve.m
deleted
100644 → 0
View file @
597279f1
# function to solve a given initial lights out problem matrix
# expects a single matrix as an argument
# solves Ax + b = c for x
# here, c is the vector describing final state of the matrix, consisting entirely of zeros
function ret = backward_solve(input)
if(nargin ~= 1),
usage("The function backward_solve expects only one argument");
end;
b = mattovec(input);
sz = size(input);
m = sz(1);
n = sz(2);
# constructing matrix A, where each entry aij contains whether the cell i is inverted or not by pressing the cell j
A = zeros(m*n, m*n);
for x= 1:m*n,
for y= 1:m*n,
# pressing the button flips its own configuration
if x == y,
A(x, y) = 1;
end;
# pressing the button flips the configuration of the button just before it, given it exists
if mod(x, n) ~= 1
&&
x  y == 1,
A(x, y) = 1;
end;
# pressing the button flips the configuration of the button just after it, given it exists
if mod(x, n) ~= 0
&&
y  x == 1,
A(x, y) = 1;
end;
# pressing the button flips the configuration of the button just above it, given it exists
if x > n
&&
x  y == n,
A(x, y) = 1;
end;
# pressing the button flips the configuration of the button just below it, given it exists
if x
<
m
*n

n
+
1
&&
y

x =
=
n
,
A
(
x
,
y) =
1;
end
;
end
;
end
;
de =
det(A);
de =
floor(de);
if
mod
(
de
,
2) =
=
0
,
de =
de
+
1
;
end
;
#
multiplying
by
an
odd
number
does
not
change
the
value
of
Ax
modulo
2
A =
floor(A);
#
the
process
requires
taking
an
inverse
,
in
some
cases
a
psuedo
inverse
is
taken
,
which
might
not
#
have
integral
values
,
thus
taking
the
floor
b =
b*de;
#
the
determinant
value
of
inverse
is
reciprocal
of
the
determinant
value
of
given
matrix
x =
(A)\b;
x =
mod(x
+
0
.
01
,
2
);
#
according
to
our
observations
,
octave
represents
numbers
very
slightly
less
than
two
to
two
.
#
in
a
few
testcases
that
we
tried
,
the
mod
function
did
the
right
thing
,
yet
the
display
was
misleading
x =
floor(x);
#
finally
representing
the
strategy
in
matrix
form
ret =
vectomat(x,m,n);
endfunction
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment