function [final] = final_state_3(init,action)
	final=zeros(3);
	A =[1,1,0,1,0,0,0,0,0;   #conversion matrix
		1,1,1,0,1,0,0,0,0;
		0,1,1,0,0,1,0,0,0;
		1,0,0,1,1,0,1,0,0;
		0,1,0,1,1,1,0,1,0;
		0,0,1,0,1,1,0,0,1;
		0,0,0,1,0,0,1,1,0;
		0,0,0,0,1,0,1,1,1;
		0,0,0,0,0,1,0,1,1];
	ini=zeros(9,1); #temporary row matrix for storing init values
	act=zeros(9,1); #temporary row matrix for storing action values
	fin=zeros(9,1); #temporary row matrix for storing final matrix values
	for i=1:3
		for j=1:3
			ini(3*(i-1)+j,1)=init(i,j);    #converting 3x3 into 9x1 matrix
			act(3*(i-1)+j,1)=action(i,j);  
		endfor
	endfor
	fin=(A*act)+ini;  
	fin=mod(fin,2);  #forming the final matrix in 9x1 format
	for i=1:3
		for j=1:3
			final(i,j)=fin(3*(i-1)+j,1);  #conversion to 3x3
		endfor
	endfor
endfunction