Use MATLAB to fit a straight line to the beam force-deflection data given in Example C.2.2, but constrain the line to pass through the origin.
We can apply (C.1.3), noting here that the measured variable is the deflection x and the independent variable is the force f . Thus (C.1.3) becomes
m \sum\limits_{i=1}^n x_i^2=\sum\limits_{i=1}^n x_i y_i (C.1.3)
m \sum\limits_{i=1}^n f_i^2=\sum\limits_{i=1}^n f_i x_i (1)
The MATLAB program to solve this equation for m and k is
% 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);
% Compute m from (1).
m = sum(f.*x)/sum(f.^2);
% Compute the stiffness.
k = 1/m
% Compute J, S, and r squared.
J = sum((m*f-x).^2)
S = sum((x-mean(x)).^2)
r2 = 1 - J/S
The answer is k = 1021 lb/in. The corresponding line is shown in Figure C.2.3. The quality-of-fit values are J = 0.0081, S = 0.5090, and r² = 0.9840, which indicates a good fit.