%Script to calculate capillary rise and plot a curve for different radii

%Surface Tension [N/m]
%Water (at 20 C): 0.073, Glycerin: 0.063, Blood (at 37 C): 0.058, Ammonia: 0.021
%Ethyl alcohol: 0.023,	 Kerosine: 0.028, Soap solution: 0.025,   Mercury: 0.440
s = 0.073;

%Contact angle (deg) - depends on liquid-solid combination
q = 0;   %For water-glass combination

%Density [kg/m^3]
rho = 990;

%Acceleration due to gravity [m/s^2]
g = 9.806;

%Minimum radius of tube [mm]
R1 = 0.25;

%Maximum radius of tube [mm]
R2 = 1.25;

%------------------------------------------------------------------------------
dr = (R2 - R1)/25;
r = [R1: dr: R2];
h = (2000 * s * cos(q*pi/180) / rho / g ./ r) * 1000;
V = pi .* r .^2 .* h / 1000;

hold on; subplot(311); 
plot(2*r, h, "linestyle", ":", "linewidth", 2, "marker", "o");
xlabel('Tube Diameter, d [mm]'); 
ylabel('Capillary Rise [mm]'); grid on;
%  
% Format X-axis ticks
  xtick = get (gca, "xtick"); 
  xticklabel = strsplit (sprintf ("%.1f\n", xtick), "\n", true);
  set (gca, "xticklabel", xticklabel)   
%  
% Format Y-Axis ticks
  ytick = get (gca, "ytick"); 
  yticklabel = strsplit (sprintf ("%.1f\n", ytick), "\n", true); 
  set (gca, "yticklabel", yticklabel);
%
subplot(312);
plot(2*r, V, "linestyle", ":", "linewidth", 2, "marker", "o");
xlabel('Tube Diameter, d [mm]'); 
ylabel('Capillary Volume [mL or cm^3]'); grid on;
%  
% Format X-axis ticks
  xtick = get (gca, "xtick"); 
  xticklabel = strsplit (sprintf ("%.2f\n", xtick), "\n", true);
  set (gca, "xticklabel", xticklabel)   
%  
% Format Y-Axis ticks
  ytick = get (gca, "ytick"); 
  yticklabel = strsplit (sprintf ("%.2f\n", ytick), "\n", true); 
  set (gca, "yticklabel", yticklabel);
%
subplot(313);
plot(2*r, V*1000, "linestyle", ":", "linewidth", 2, "marker", "o");
xlabel('Tube Diameter, d [mm]'); 
ylabel('Capillary Volume [\muL]'); grid on;
%  
% Format X-axis ticks
  xtick = get (gca, "xtick"); 
  xticklabel = strsplit (sprintf ("%.2f\n", xtick), "\n", true);
  set (gca, "xticklabel", xticklabel)   
%  
% Format Y-Axis ticks
  ytick = get (gca, "ytick"); 
  yticklabel = strsplit (sprintf ("%.0f\n", ytick), "\n", true); 
  set (gca, "yticklabel", yticklabel);