%The analytic function
trueAnswer=33/16;
limitsOfIntegration=[1/2,2];
f  = @(x) x.^3/6 + 1./(2*x);
fd = @(x) 1/2*(x.^2 - 1./ x.^2);


%create the vectors
x=linspace(1/2,2,100);
y=f(x);

%plot the values
figure; plot(x,y)

%diff
dx=diff(x);
dy=diff(y);

a1=sum(sqrt(dx.^2+dy.^2));

disp(['The sum approximation was off by ' num2str((a1-trueAnswer)/trueAnswer*100) '%'])
%
f_arc=@(x) sqrt(1+fd(x).^2);
a2=quad(f_arc,limitsOfIntegration(1),limitsOfIntegration(2));
disp(['The quad integration approximation was off by ' num2str((a2-trueAnswer)/trueAnswer*100) '%'])


limitsOfIntegration=[1/2,2];
fd = @(x) 1/2*(x.^2 - 1./ x.^2);
f_arc=@(x) sqrt(1+fd(x).^2);
a2=quad(f_arc,limitsOfIntegration(1),limitsOfIntegration(2));