function f=fenceDem(infile, outfile) %open infile for read in = fopen(infile,'r'); %open outfile for write out = fopen(outfile, 'w'); %get input from infile %the values are in vector y and the total number of values is in "count" [y, count] = fscanf(in, '%d', inf); %calculate all pairs (using for loop) for i=1:1:count/2 W = y(2*i-1); A = y(2*i); % we know % WL + 0.5*D^2 = A, and % W=sqrt(2)*D % so we have WL + 0.25*W^2 = A % solve this equation and we get L = (A-0.25*W^2)/W; %output the L value to outfile fprintf(out, '%f\n', L); end %close all the files we opened fclose(in); fclose(out);