<< Chapter < Page Chapter >> Page >
Basic curve fitting and linear regression.


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.

Vehicle velocity versus time.
Time [s] Velocity [m/s]
0 20
10 39
20 67
30 89
40 111
50 134
60 164
70 180
80 200

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:

y m x 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.

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.

A new variable is created in the Workspace.

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:

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:

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 .

The following is a collection of data for an iron-constantan thermocouple (data available for download ). Engineering Fundamentals and Problem Solving by Arvid R. Eide, Roland Jenison, Larry L. Northup, Steven K. Mikelson , McGraw-Hill Higher Education. © 2007 p.114

Temperature [C] vs Voltage [mV]
Temperature [C] Voltage [mV]
50 2.6
100 6.7
150 8.8
200 11.2
300 17.0
400 22.5
500 26
600 32.5
700 37.7
800 41
900 48
1000 55.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;26;32.5;37.7;41;48;55.2]

To plot the graph, type in:


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

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.

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.052831 x 0.67202 This equation can be entered as polynomial and evaluated at 650 and 1150 as follows:

>>p=[0.052831,0.67202] p =0.0528 0.6720>>polyval(p,1150) ans =61.4277

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.

Questions & Answers

do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
Do somebody tell me a best nano engineering book for beginners?
s. Reply
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
many many of nanotubes
what is the k.e before it land
what is the function of carbon nanotubes?
I'm interested in nanotube
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
preparation of nanomaterial
Victor Reply
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
Himanshu Reply
good afternoon madam
what is system testing
what is the application of nanotechnology?
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
anybody can imagine what will be happen after 100 years from now in nano tech world
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
silver nanoparticles could handle the job?
not now but maybe in future only AgNP maybe any other nanomaterials
I'm interested in Nanotube
this technology will not going on for the long time , so I'm thinking about femtotechnology 10^-15
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Berger describes sociologists as concerned with
Mueller Reply
Got questions? Join the online conversation and get instant answers!
QuizOver.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, A brief introduction to engineering computation with matlab. OpenStax CNX. Nov 17, 2015 Download for free at http://legacy.cnx.org/content/col11371/1.11
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'A brief introduction to engineering computation with matlab' conversation and receive update notifications?