s=load("input_outlab_task_A2.txt");  %loading the input values
x1=s(1);y1=s(2);v2=s(3);vl=s(4);d=s(5);w=s(6);n=s(7);t1=s(8);  %assigning the values

                 %f=@(x)  ((cot(x)*cos(x)*vl)-v2)*(y1-w+((w*n*n*cos(x))/sqrt((n*n)-sin(x)*sin(x))))-(((cos(x)*vl)-v2)*((cot(x)*(y1-d-w))+((w*cos(x)*cos(x)*n)/sqrt((n*n)-(sin(x)*sin(x))))+d));
                 %t=((((v2*t1)+y1-w)/(cos(x)*vl))+((w*n*n)/sqrt((n*n)-(sin(x)*sin(x)))*vl))/(1-(v2/(cos(x)*vl)));

f=@(x) ((tan(x)*(y1-d-w))+(w*(sin(x)/sqrt((n*n)-(sin(x)*sin(x)))))+(tan(x)*(d+(v2*(((((v2*t1)+y1-w)/(cos(x)*vl))+((w*n*n)/sqrt((n*n)-(sin(x)*sin(x)))*vl))/(1-(v2/(cos(x)*vl)))+t1))))-x1); %function made after doing the calculation

l=fsolve(f,0.1); %returns in radians
t=((((v2*t1)+y1-w)/(cos(l)*vl))+((w*n*n)/sqrt((n*n)-(sin(l)*sin(l)))*vl))/(1-(v2/(cos(l)*vl))); %calculates total time taken to hit the shields

m=(l*180.0)/pi; %returns in degrees
g=x1; %assigning g 
y=y1+(v2*(t+t1));  %returns the final y coordinate of the X1 plane 

a = [m g y];
csvwrite("output_outlab_task_A2.txt",a); %prints the output in the given file





















































































































































































































































































































