function [AR,xLE]=ARfit(P,t) global tmax % This function calculates the AR of a rectangle fitted inside an airfoil % described by the cubic spline function in P. The value t is the thickness % if the required rectangle (tmax-x1) tsave=t; t=tmax-x1; flag=2; elseif (t0); thetaTE=reversefit(P,t/2,theta(roots(1))); rTE=ppval(P,thetaTE); xTE=rTE*cos(thetaTE); thetaLE=reversefit(P,t/2,theta(roots(2))); rLE=ppval(P,thetaLE); xLE=rLE*cos(thetaLE); l=abs(xTE-xLE); AR=l/t; if flag==1 x3=2*x1; y1=AR; y2=1.1*AR; a = (y1-y2)/(-2*x3*x1+x1^2); b=(y1-a*x1^2-y2)/x1; AR=a*tsave^2+b*tsave+y2; elseif flag==2 x3=tmax-x1*.001; x2=tmax; x1=tmax-2*x1; a=-AR/((x2^2-x3^2)-2*x1*(x2-x3)); b=-2*a*x1; c=-a*x2^2-b*x2; AR=a*tsave^2+b*tsave+c; end;