Presentation is loading. Please wait.

Presentation is loading. Please wait.

ABE425 Engineering Measurement Systems Ordinary Least Squares (OLS) Fitting Dr. Tony E. Grift Dept. of Agricultural & Biological Engineering University.

Similar presentations


Presentation on theme: "ABE425 Engineering Measurement Systems Ordinary Least Squares (OLS) Fitting Dr. Tony E. Grift Dept. of Agricultural & Biological Engineering University."— Presentation transcript:

1 ABE425 Engineering Measurement Systems Ordinary Least Squares (OLS) Fitting Dr. Tony E. Grift Dept. of Agricultural & Biological Engineering University of Illinois

2 First, we need to talk about linearity In Mathematics, there are linear and non-linear operations: If an operation is linear, the superposition principle can be applied:

3 Examples Multiplication by a constant c (linear)

4 Examples Differentiation (linear)

5 Examples Integration (linear)

6 Examples Squaring (non-linear)

7 Examples Square root (non-linear)

8 Try these:

9 You collected a set of data pairs (for example temperature versus time >> x=[0:1:10]' >> y = [0.5 0.75 1.25 1.3 2.1 2.0 3.1 3.05 4.0 4.5 5]'

10 Model is some function of the independent variable and the parameter vector. You choose the model!! The error is the difference between a data point and the corresponding model Error = Data - Model

11 The idea of using the sum of least squared errors came from Gauss (first published by Legendre): How can we minimize this error with respect to the parameter vector? In other words, how can we find the parameter vector that minimizes the error and maximizes the fit? “Sur la Méthode des moindres quarrés” in Legendre’s Nouvelles méthodes pour la détermination des orbites des comètes, Paris 1805.

12 The minimum value of the sum of squares is obtained by setting this partial derivative to zero The derivative is partial, because the Sum of residuals S is a function of the error and the error itself is a function of the parameter vector (remember the chain rule):

13 The minimum value of the sum of squares is obtained by setting this partial derivative to zero Substitution of the results from the previous slide gives: Now, we need to find out what is

14 The proposed model is linear in the parameters. Here is an polynomial example: For each i th measurement this can be written using a matrix and a parameter vector as follows: This can also be written as:

15 For all measurement points we obtain: This can also be written in vector form as: Where A is the regressor matrix

16 From the model definition we can obtain the partial derivative with respect to the parameter vector By replacing the error with the (data – model) we get :

17 Upon rearrangement these become n simultaneous linear equations, the normal equations.

18 Here a second order polynomial with intercept was applied

19 Determine whether the data needs an intercept. Often physical constraints demand that the fit curve passes through the origin! No intercept!

20 OLS lab function [theta, msq] = fitols(x,y,Ovec) % Fit polynomial function on data in OLS sense % Author : % Date : % Revision : % % Syntax : [theta,msq] = fitols(x,y,Ovec) % % theta : Parameter vector % msq : Mean square error % x : Independent variable % y : Dependent variable % % Ovec indicates terms [1 x x^2..]*Ovec' % Example Ovec = [1 0 1] gives [1 x^2] and not x % If vectors x,y are horizontal, transpose them to make them vertical % Make sure the x and y vector have the same length. If not alert the user % with an error dialog box (type help errordlg ) % Build the matrix of regressors. Check each entry of Ovec, and if it is a % 1, add another column to the regression matrix A. A = []; % Compute the parameter vector theta using the OLS formula % Compute the error vector % Compute the mean square error which indicates how good the fit is % Plot y (Temperature in C) versus x (Current in A). Add labels and title. % Your output should look as shown in the handout.

21 ABE425 Engineering Measurement Systems Ordinary Least Squares (OLS) Fitting The End Dept. of Agricultural & Biological Engineering University of Illinois


Download ppt "ABE425 Engineering Measurement Systems Ordinary Least Squares (OLS) Fitting Dr. Tony E. Grift Dept. of Agricultural & Biological Engineering University."

Similar presentations


Ads by Google