A Brief Introduction to Engineering Computation with MATLAB by Serhat Beyenir - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Chapter 7Regression Analysis

7.1Linear Regression*

Basic curve fitting and linear regression.

RegressionAnalysis

What is Regression Analysis?

Suppose we calculate some variable of interest, y, as a function of some other variable x. We call y the dependent variable and x the independent variable. For example, consider the data set below, taken from a simple experiment involving a vehicle, its velocity versus time is tabulated. In this case, velocity is a function of time, thus velocity is the dependent variable and the time is the independent variable.

Table 7.1. Vehicle velocity versus time.
Time [s]Velocity [m/s]
020
1039
2067
3089
40111
50134
60164
70180
80200

In its simplest form regression analysis involves fitting the best straight line relationship to explain how the variation in a dependent variable, y, depends on the variation in an independent variable, x. In our example above, once the relationship (in this case a linear relationship) has been estimated we can produce a linear equation in the following form:

(7.1) y=mx+n

And once an analytic equation such as the one above has been determined, dependent variables at intermediate independent values can be computed.

Performing Linear Regression

Regression analysis with MATLAB is easy. The MATLAB Basic Fitting GUI allows us to interactively to do "curve fitting" which is a method to arrive at the best "straight line" fit for linear equations or the best curve fit for a polynomial up to the tenth degree. The procedure to perform a curve fitting with MATLAB is as follows:

  1. Input the variables,

  2. Plot the data,

  3. Initialize the Basic Fitting GUI,

  4. Select the desired regression analysis parameters.

Example 7.1

Using the data set above, determine the relationship between velocity and time.

First, let us input the variables (Workspace > New variable) as shown in the following figures.

NewVariable
Figure 7.1
A new variable is created in the Workspace.

NewVariable
Figure 7.2
New variables are entered in the Variable Editor.

Second, we will plot the data by typing in plot(time,velocity) at the MATLAB prompt. The following plot is generated, select Tools > Basic Fitting:

NewVariable
Figure 7.3
A plot is generated in Figure 1. The Basic Fitting tool can be initialized from Tools > Basic Fitting.

In the "Basic Fitting" window, select "linear" and "Show equations". The best fitting linear line along with the corresponding equation are displayed on the plot:

NewVariable
Figure 7.4
Basic Fitting window is used to select the desired regression analysis parameters.

Now let us do another curve fitting and obtain an equation for the function. Using that equation, we can evaluate the function at a desired value with polyval.

Example 7.2

The following is a collection of data for an iron-constantan thermocouple (data available for download). [12]

Table 7.2. Temperature [C] vs Voltage [mV]
Temperature [C]Voltage [mV]
502.6
1006.7
1508.8
20011.2
30017.0
40022.5
50026
60032.5
70037.7
80041
90048
100055.2
  1. Plot a graph with Temperature as the independent variable.

  2. Determine the equation of the relationship using the Basic Fitting tools.

  3. Estimate the Voltage that corresponds to a Temperature of 650 C and 1150 C.

We will input the variables first:

Temp=[50;100;150;200;300;400;500;600;700;800;900;1000]
Voltage=[2.6;6.7;8.8;11.2;17;22.5;36;32.5;37.7;41;48;55.2]

To plot the graph, type in:

plot(Temp,Voltage)

We can now use the Plot Tools and Basic Fitting settings and determine the equation:

NewVariable
Figure 7.5
Basic Fitting window is used to select the desired regression analysis parameters.

By clicking the right arrow twice at the bottom right corner on the Basic Fitting window, we can evaluate the function at a desired value. See the figure below which illustrates this process for the temperature value 1150 C.

Evalu
Figure 7.6
Estimating the Voltage that corresponds to a Temperature of 1150 C.

Now let us check our answer with a technique we learned earlier. As displayed on the plot, we have obtained the following equation: y=0.053x+1.4 This equation can be entered as polynomial and evaluated at 650 and 1150 as follows:

>> p=[0.053,1.4]

p =

    0.0530    1.4000

>> polyval(p,650)

ans =

   35.8500

>> polyval(p,1150)

ans =

   62.3500

Summary of Key Points

  1. Linear regression involves fitting the best straight line relationship to explain how the variation in a dependent variable, y, depends on the variation in an independent variable, x,

  2. Basic Fitting GUI allows us to interactively perform curve fitting,

  3. Some of the plot fits available are linear, quadratic and cubic functions,

  4. Basic Fitting GUI can evaluate functions at given points.

Solutions