function C = calc_c(xi,yi,xo,yo,n)

% ******************************************************************

%  MATLAB FUNCTION calc_c.m

% Calculate the curvature ratio for a valley cross profile

%  Inputs
%  xi: x co-ordinates (distance) of inner sub-section  [metres]
%  yi: y co-ordinates (elevation) of inner sub-section  [metres]
%  xi: x co-ordinates (distance) of outer sub-section  [metres]
%  yi: y co-ordinates (elevation) of outer sub-section  [metres]
%  n: degree of polynomial [script is currently set up for degree 2]

%  Outputs
%  C: ratio between the curvature of the inner and outer sub-sections

% *******************************************************************

% Fit polynomial to inner section
p_i = polyfit(xi,yi,n);
curv_i = 2*p_i(1)*(xi(end)-xi(1));

% Fit polynomial to outer section
p_o = polyfit(xo,yo,n);
curv_o = 2*p_o(1)*(xo(end)-xo(1));

% C ratio
C = 1 - (curv_i / curv_o);

end


