%DISTANCEFIT2: MATLAB script M-file that fits the distance %function stored in distvec.m to data. %define data %Author: Peter Howard theta = 5:5:85; dexp = [4.37 5.23 6.95 7.84 8.17 8.69 8.81 8.99 8.95 8.83 8.19 7.84 7.12 6.38 5.08 3.34 2.13]; E = @(p) norm(dexp-distvec(p(1),p(2)))^2; %Here, p(1)=v0, p(2)=b guess = [12.25450 .0645]; %Initial guess [p error]=fminsearch(E,guess) % %Final fit plot(theta,dexp,'o',theta,distvec(p(1),p(2))) title({'Plot of Horizontal Distances, model and data', 'Fit using 17 data points'},'FontSize',15) xlabel('Angle of Inclination') ylabel('Horizontal Distance Traveled') legend('Experimental data','Model') sse =norm(distvec(p(1),p(2))-dexp)