Explore BrainMass

Matlab normal equations without polyfit

See attached file for full problem description.

Does anyone know how to do this without using Matlab functions such as polyfit and etc? The regression and error analysis needs to be performed by solving the normal equations. I also attached an example of how it is supposed to be modeled.

%Tossing a lead weight: example of linear regression error from BME221 lecture

%matrix of modeling functions: first column of ones, second column = t,
%third column = -0.5*t^2 (data is modeled by h = h0 +V0*t +0.5g*t^2).
%We shall denote our model by the vector equation A*x=b
%height measurements in meters
h=[0.3 14.8 20.7 15.9 2]'
% our modeling parameters, (h0,V0,g)
%variance in data
%variance in first modeling parameter, for demonstration only.
%other variances and covariances can be extracted from the symmetric SIGMAxsq.
%SIGMAbsq: matrix of covariance of the observations b.
%If the observations are independent then SIGMAbsq will be diagonal only.
%We further assume that all observations have the same variance.
%(a common assumption)
%matrix of covariance of the regression parameters
%Suppose we wish to determine the model value at 100 points ranging from 0 to 4.
%Thus, we now have the vector equation: bm = Am*x
%Finally, we have the matrix of covariance of bm.
%In general, only the diagonal elements of SIGMAbmsq are of interest.
hold on
hold off
legend('data','best-fit model','69% confidence (1sigma) interval')
xlabel('t (sec)')
ylabel('h (m)')


Solution Preview

The example you gave did indeed help.

The attached file follows the example you gave.

function Michaelis3()

% Data for Rxn rate with progesterone - case 1: with progesterone
dog1 = [ 5 10 20 25 30 40 50 60 ] ; % dog is C in the formula
rxn1 = [ 3.25 2.4 5.1 6 7.2 7.7 9.1 9.05 ] ; % Rxn is R in the formula

% The variables in which we do linear regression:
% x = 1/C and y = 1/R
x1 = 1./dog1' ;
y1 = 1./rxn1' ;

% model: y1 = (Km/Rmax)*x1 + (1/Rmax)
% matrix of modeling functions:
A1 = [ ones(1,length(x1)) ; x1' ]' ;
K1 = inv(A1'*A1)*A1'
% Modeling parameters: ModPars = [ (1/Rmax), (Km/Rmax) ]
ModPars1 = K1 * y1

% Now we know what Km and Rmax are in the fit:
Rmax1 = 1/ModPars1(1)
Km1 = ModPars1(2)/ModPars1(1)
% This answers the 1st question
% but we also have to look for confidence intervals

% Data Variance: subtract 2 as here we have 2 modeling parameters
% and so used 2 degrees of freedom in the ...