function [estimates, model] = fitvad(azdata, ydata)
% Call fminsearch with a random starting point.
start_point = rand(1, 2);
model = @cosfun;
estimates = fminsearch(model, start_point);
% expfun accepts curve parameters as inputs, and outputs sse,
% the sum of squares error for A * exp(-lambda * xdata) - ydata, 
% and the FittedCurve. FMINSEARCH only needs sse, but we want to 
% plot the FittedCurve at the end.
    function [sse, FittedCurve] = cosfun(params)
        A = params(1);
        B = params(2);
        FittedCurve = A.*cosd(azdata+B);
        ErrorVector = FittedCurve - ydata;
        sse = sum(ErrorVector .^ 2);
    end
end