The force-deflection data from Example 1.3.1 for the cantilever beam shown in Figure 1.3.1 is given in the following table.
Use MATLAB to obtain a linear relation between x and f, estimate the stiffness k of the beam, and evaluate the quality of the fit.
800 | 700 | 600 | 500 | 400 | 300 | 200 | 100 | 0 | Force f (lb) |
0.77 | 0.68 | 0.57 | 0.5 | 0.37 | 0.35 | 0.23 | 0.15 | 0 | Deflection x (in.) |
Note that here X is the dependent variable and f is the independent variable. In the following MATLAB script file the data are entered in the arrays \boxed{x} and \boxed{f}. The arrays \boxed{xp} and \boxed{fp} are created to plot the straight line at many points.
% Enter the data.
x = [0, 0.15, 0.23, 0.35, 0.37, 0.5, 0.57, 0.68, 0.77];
f = (0:100:800);
% Fit a first-degree polynomial.
p = polyfit(f,x,1)
% Compute the stiffness.
k = 1/p(1)
% Compute a set of f, x points.
fp = (0:800);
xp = p(1)*fp+p(2);
% Plot the fitted function and the data.
plot(fp,xp,f,x,'o'), xlabel('Applied Force f (lb)'), ...
ylabel('Deflection x (in.)'), ...
axis([0 800 0 0.8])
% Compute the J, S, and r squared values.
J = sum((polyval(p,f)-x).^2)
S = sum(x-mean(x)).^2)
r2 = 1 - J/S
The computed values in the array \boxed{p} are p = [9.1667 × 10^{−4}, 3.5556 × 10^{−2}]. Thus the fitted straight line is x = 9.1667 × 10^{−4} f + 3.5556 × 10^{−2}. Note that this line, which is shown in Figure C.2.2, does not pass through the origin as required, but it is close (it predicts that x = 0.035556 in. when f = 0). The quality-of-fit values are J = 0.0048, S = 0.5090, and r² = 0.9906, which indicates a very good fit.
Solving for f gives f = (x − 3.5556 × 10^{−2})/9.1667 × 10^{−4} = 1091x − 38.7879. The computed value of the stiffness k is the coefficient of x; thus k = 1091 lb/in.