In: Mechanical Engineering
The following data give the stopping distance d as a function of initial speed υ, for a certain car model. Find a quadratic polynomial that fits the data. Determine the quality of the curve t by computing J, S, and r2.
Determine the quality of the curve fit by computing J, S, and r2.
The following data gives the stopping distance d as a function of initial speed v
To plot the above data set and to curve fit in MATLAB type the below code in script:
%enter the values of v
v = 20:10:70;
%enter the values of d
d = [45,80,130,185,250,330];
%give step increment for v
vf = 20:0.1:70;
%use ployfit command
p = polyfit(v,d,2);
df = polyval(p,vf);
J = sum((polyval(polyfit(v,d,2),v)-d).^2);
%use plot command
plot(vf,df,v,d,'*')
%give axis start values
axis([20 70 0 350])
%give y axis label
ylabel('d(ft)')
%give x axis label
xlabel('v(mi/hr)')
m = mean(d);
S = sum((d-m).^2);
r2 = 1-J/S;
J
S
r2
Now, RUN the code,
The plot display as follows:
And in command window results will prompt
The results are J = 10.1786 for the first through fourth-order polynomials. In addition, S = 57550 and r2 = 0.9998.
The results are J = 10.1786 for the first through fourth-order polynomials. In addition, S = 57550 and r2 = 0.9998.