%
%   HORIZONTAL_CYL_1.M     Find the volume & height of fluid 
%                          in a horizontal cylindrical tank
%
%   The volume of fluid in a horizontal cylindrical tank is given by:
%       V = L*(R*R*acos((R-h)/R)-(R-h)*sqrt(2*R*h-h*h))
%   where V = volume, R = radius, h = height of fluid, and L = length of tank.
%
%   Problem description:  
%      a.  If h, R, and L are known, find V.  --  this is explicit
%      b.  If V, R, and L are known, find h.  --  this is implicit
%
%   The explicit problem is simple and uses a single explicit evaluation.  The
%   implicit problem uses fzero, with the function file HORIZONTAL_CYL_1A.M to
%   find the value of h that satisfies the implicit form, f(h) = 0, of the above
%   equation.
%
%   File prepared by J. R. White, UMass-Lowell  (last update:  Nov. 2017)
%

      clear all,   close all
      global R L Vol
%
%   Part a:  Find Volume of Fluid in a Horizontal Cylindrical Tank
      R = 2.5;  L = 5;    % radius and length of tank (m)
      ha = 3.0;           % height of fluid for Part a of problem  (m)
      Va = L*(R*R*acos((R-ha)/R)-(R-ha)*sqrt(2*R*ha-ha*ha));
      fprintf('\n\n  Lesson 5 Prob. #1a  --> Height of fluid in tank = %8.5f m  \n ',ha);
      fprintf('                     --> Volume of fluid in tank = %8.5f m^3  \n ',Va);
%
%   Part b:  Find Height of Fluid in a Horizontal Cylindrical Tank
      Vb = 1.5+Va;      % volume after adding another 1.5 m^3 of fluid
      fprintf('\n\n  Lesson 5 Prob. #1b  --> Volume of fluid in tank = %8.5f m^3  \n ',Vb);
      Vol = Vb;         % volume of fluid to pass to function subroutine used by fzero
      hb = fzero(@horizontal_cyl_1a,[0 2*R]);
      fprintf('                     --> Height of fluid in tank = %8.5f m  \n ',hb);
%
%  end of problem

