%
%   SLANTED_GATE_1A.M   Function file for use in FMINBND  
%
%   This file evaluates the rod force, Frod, for any gate angle, th.   
%   This function is used in the last part of the slanted_gate_1.m file.
%   It contains much of the calculations done in the earlier parts of
%   the program.  If our real focus had only been the rod force, this
%   would have been the only major component needed.
%
%   File prepared by J. R. White, UMass-Lowell (last update:  Nov. 2017)
%
      function Frod = slanted_gate_1a(th,a,B,L,Vw,W,spwt)
%   
%   compute h  (see eqn. 2 in notes)
      Nth = length(th);  h = zeros(1,Nth);
      for i = 1:Nth
        p = [B*tan(th(i))/2 a*B -Vw];  rr = roots(p);  h(i) = max(rr);
      end
%   
%   compute FR and ycp  (see eqns. 3 and 5 in notes)
      FR = spwt*B*h.*h./(2*cos(th));  ycp = h./(3*cos(th));
%
%   compute angle alpha  (see eqn. 8 in notes)
      alpha = th + acos(cos(th)/sqrt(2));
%
%   now compute Frod  (see eqn. 6 in notes)
      Frod = (FR.*ycp + W*sin(th)*L/2)./(L*sin(alpha));
%
%   end of function

