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);
