Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs251_group23
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
TARUN OMPRAKASH VERMA
cs251_group23
Commits
fcaaf8af
Commit
fcaaf8af
authored
Aug 23, 2016
by
HARSH DEPAL
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Outlab 1
parent
db23a515
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
136 additions
and
0 deletions
+136
-0
lab01_group23_final/Readme.txt
lab01_group23_final/Readme.txt
+28
-0
lab01_group23_final/backward_solve.m
lab01_group23_final/backward_solve.m
+32
-0
lab01_group23_final/backward_solve_3.m
lab01_group23_final/backward_solve_3.m
+32
-0
lab01_group23_final/guass_elim.m
lab01_group23_final/guass_elim.m
+27
-0
lab01_group23_final/main_task_A1.m
lab01_group23_final/main_task_A1.m
+5
-0
lab01_group23_final/main_task_A2.m
lab01_group23_final/main_task_A2.m
+12
-0
No files found.
lab01_group23_final/Readme.txt
0 → 100644
View file @
fcaaf8af
Group number 23
Group members:
(Harsh Depal, 150050010),(Tarun Verma, 150050021),(Bhavya Choudhary, 150050028)
Honor code:-
I pledge on my honour that I have not given or received
any unauthorized assistance on this assignment or any previous task.
Individual Percentage :
Harsh Depal:100%, Tarun Verma:100%, Bhavya Choudhary:100%
Citations:
www.math.utah.edu
stackoverflow.com
gnu.org
www.dm.unibo.it
tutorialspoint.com
http://www.ueda.info.waseda.ac.jp/~n-kato/lightsout/
wikipedia.org
Brief Reflection :
We had study little bit of modular arithmatics for matrices to solve the Lights Out puzzle.
As we couldn't find a function can do modular arithmatic in Octave we had to write our own functions using for loops.
We learned how octave with its powerful built-in functions can be used to solve complicated mathematical equations.
\ No newline at end of file
lab01_group23_final/backward_solve.m
0 → 100644
View file @
fcaaf8af
function action = backward_solve_3(cstate)
[row,col]=size(cstate);
M=[]; # M will become the matrix where Mij = 1 ⇐⇒ button i is toggled on pressing button j
for x=1:row*col
for y=1:row*col
if(abs(y-x) == col | (abs(y-x)
<
=
1
&
floor
((
y-1
)/
col)=
=floor((x-1)/col)))
v(y)=
1;
else
v(y)=
0;
endif
endfor
M=
[M;v];
#
adding
ith
column
as
a
row
.
we
will
transpose
it
later
endfor
for
i=
1:row
for
j=
1:col
w
((
i-1
)
*col
+
j)=
cstate(i,j);
#
converting
cstate
into
vector
endfor
endfor
M=
[M;w];
#
making
augmented
matrix
M =
M';
guassM=
guass_elim(M);
#
last
column
is
the
answer
,
doing
guass
elimination
action=
[];
for
l=
1:row
#
converting
last
column
as
a
matrix
for
k=
1:col
Arow(k)=
guassM((l-1)*col+k,col*row+1);
endfor
action=
[action;Arow];
endfor
endfunction
lab01_group23_final/backward_solve_3.m
0 → 100644
View file @
fcaaf8af
function action = backward_solve_3(cstate)
[row,col]=size(cstate);
M=[]; # M will become the matrix where Mij = 1 ⇐⇒ button i is toggled on pressing button j
for x=1:row*col
for y=1:row*col
if(abs(y-x) == col | (abs(y-x)
<
=
1
&
floor
((
y-1
)/
col)=
=floor((x-1)/col))
)
v(y)=
1;
else
v(y)=
0;
endif
endfor
M=
[M;v];
#
adding
ith
column
as
a
row
.
we
will
transpose
it
later
endfor
for
i=
1:row
for
j=
1:col
w
((
i-1
)
*col
+
j)=
cstate(i,j);
#
converting
cstate
into
vector
endfor
endfor
M=
[M;w];
#
making
augmented
matrix
M =
M';
guassM=
guass_elim(M);
#
last
column
is
the
answer
action=
[];
for
l=
1:row
#
converting
last
column
as
a
matrix
for
k=
1:col
Arow(k)=
guassM((l-1)*col+k,col*row+1);
endfor
action=
[action;Arow];
endfor
endfunction
lab01_group23_final/guass_elim.m
0 → 100644
View file @
fcaaf8af
# function to solve the matrix "augmented" by guassian elimination with modular arithematic and return the guass jordan form as the final "matrix"
function final = guass_elim(augmented)
final = augmented;
n = size(final,1); # n stores the number of rows in final
for i = 1 : n
if (final(i,i)!=1)
# for loop to make i,i position 1 by row operations
for a = i : n
if (final(a,i) == 1)
final(i,:) = mod((final(i,:) + final(a,:)),2);
break;
endif
endfor
endif
# for loop to make all elements of column i 0 except i,i
for a = 1 : n
if (final(a,i) == 1
&&
a!=i)
final(a,:) = mod((final(i,:) + final(a,:)),2);
endif
endfor
endfor
endfunction
\ No newline at end of file
lab01_group23_final/main_task_A1.m
0 → 100644
View file @
fcaaf8af
filename = "input_outlab_task_A1.txt";
[x1,y1,d,w,n] = textread(filename,"%f %f %f %f %f"); #reading data from input file
f = @(x) [(y1-w)*tand(x(1)) + w*tand(x(2)) - x1;n*sind(x(2)) - sind(x(1))];
x = fsolve(f,[0;0]); # using fsolve to find the required values
csvwrite("output_outlab_task_A1.txt",x(1)); #writing the calculated answer in the output file
\ No newline at end of file
lab01_group23_final/main_task_A2.m
0 → 100644
View file @
fcaaf8af
inputfile = "input_outlab_task_A2.txt";
outputfile = "output_outlab_task_A2.txt";
[xt,yt,xx,yx,v2,vl,d,w,n,t1] = textread(inputfile,"%f %f %f %f %f %f %f %f %f %f"); # reading data from input file
x1 = xx - xt;
y1 = yx - yt + t1*v2;
f = @(x) [sind(x(1))-n*sind(x(2));(y1 + ((y1-w+w*n*cosd(x(1))/cosd(x(2)))/(vl*cosd(x(1))-v2))*v2)*tand(x(1)) + w*(tand(x(2))-tand(x(1))) - x1];
x = fsolve(f,[0;0]); # using fsolve to find required vector x
xf = xx;
yf = yx + t1*v2 + ((y1-w+n*w*cosd(x(1))/cosd(x(2)))/(vl*cosd(x(1))-v2))*v2; # calculating final coordinates xf and yf
ofile = fopen(outputfile,"w");
fprintf(ofile,"%f %f %f",x(1),xx,yf); # writing the calculated answer in output file
fclose(ofile);
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