% VDV - Calculate volume function and its derivative: % [V,DV] = VDV(THETA) % THETA must be in radians. Function is correctly vectorized. % Reads global variables V_D, R, R1 % Philip D Loewen, 2010-02-24; 2011-03-15 function [V,dV] = vdv(theta) global global_V_D global_r global_R1 % Make local copies to make formulas more readable. V_D= global_V_D; r = global_r; R1 = global_R1; % Compute the square root just once, for efficiency: radical = (R1^2 - sin(theta).^2).^(0.5); V = V_D/(r-1) + 0.5 * V_D * (1 + R1 - cos(theta) - radical); dV = 0.5 * V_D * sin(theta) .* (1 + cos(theta)./radical);