a=load('input_outlab_task_A1.txt'); # takes input from the file and store in vector

global x1=a(1);
global y1=a(2);
global d=a(3);										#assign respective values in variables from the vector
global w=a(4);
global n=a(5);

function y=f(x)
	global x1;
	global y1;
	global d;										#variable declaration inside the function
	global w;
	global n;
	y(1)=x(1)+x(2)+x(3)-x1;
	y(2)=tan(x(4))*(y1-d-w)-x(1);
	y(3)=tan(x(5))*w-x(2);							#equation which are to be solved
	y(4)=tan(x(4))*d-x(3);
	y(5)=sin(x(4))-n*sin(x(5));
endfunction

[x,info]=fsolve("f",[0;0;0;0;0]);					#solves the equation using fsolve
fileID = fopen('output_outlab_task_A1.txt','w');	
fprintf(fileID,'%4.1f\n',x(4)*180/pi);				#reads the output in file 
fclose(fileID);