Gnuplot/C2/Error-bars-and-data-fitting/English

From Script | Spoken-Tutorial
Revision as of 16:09, 11 March 2019 by Ranipv076 (Talk | contribs)

Jump to: navigation, search
Visual Cue Narration
Slide Number 1

Title Slide Data fitting and error bars

Welcome to the tutorial on Data fitting and error bars
Slide Number 2

Learning Objectives

In this tutorial, we will learn,
  • Learn to add error bars in a graph
  • Learn data fitting
  • Fit a given dataset to an equation
  • Run non-linear regression and generate fitting parameters
Slide Number 3

System and Software Requirement

*Debian Linux 9 .3
  • Gedit 3.22.0 and
  • gnuplot 5.2.5 installed
Slide Number 4

Pre-requisites

To follow this tutorial, learner’s must be familiar with,
  • Basic computer and internet skills
  • Concept of graphing and
  • College level Mathematics skills
Go to Desktop. First, we will first learn to incorporate error bars in a graph.

First, Go to Desktop. I have a, x y yerror type data, in a text file.

Double click to open the file. It is saved in Desktop directory for me.

Double click on the file icon to open it in a text editor. The file opens in gedit for me. This file is provided to you with the tutorial.

Hover mouse over columns The first column is x data.

Second column is y data. The third column is y data error bar in measurement.

Close gedit Close gedit by clicking on the x-sign.
Press ctrl alt t

cd ~/Desktop

Press ctrl alt t keys together to open a terminal.

Change directory to Desktop as seen on the screen.

gnuplot Open gnuplot.

Type gnuplot and enter

Show qt on screen. Set terminal as necessary.

For me it is already in qt.

Ctrl-l I will clear screen with command control l.

This takes terminal prompt to top of the screen for clarity in video.

First, let's plot the data to see the trend and for visual inspection.
plot 'error-bar.txt' using 1:2:3 with yerrorbars Enter the plot command as seen on the screen.
If error limits are on the x data, we can use, x error bars term for plotting.

The graphic window opens.

The colon 3 with y error bars in the plot command adds the error to the plot.
Hover mouse over decay curve. Next, let's fit this graph to an equation.
This data likely represent an exponential decay.
The points may be off the ideal curve due to measurement errors.
We will fit the given data points to an exponential decay function.
Let's see a few steps involved in fitting data points to an equation.
Slide Number 5

Steps in data fitting

First, define a function to represent the data

Make initial guess values for constants A good fitting, measured by chi square value Find the 'optimal' value of the constants in the function and Display the fitted data

f(x) = a * exp(-k*x) First, let's define the function.

Type f of x is equal to a times e to the power minus k x Use the syntax as seen on the screen

Go to graphical window. Let's make an educated initial guess for the initial guess values of a and k

Go to graphical window.

From the graph, I will place the initial value of a at one lakh fitfty thousand
For an exponential decay, I will place the initial guess of k around 0.5
Close the graphical window and go to gnuplot terminal prompt.
a=150000

k=0.5

Enter commands to set the values of a and k

Enter a equal to fifteen hundred thousand Enter k equal to zero point five

fit f(x) “error-bar.txt” using 1:2:3 via a,k To fit the data use command as seen on the screen.

Fit space f of x space in double quotes error hyphen bar dot txt. Then Space using space 1 colon 2 colon 3 via a comma k

If column 3 is not mentioned, the y axis uncertainties is not considered for data fitting.
The software does the fitting and gives output values.
Let's scroll up the screen.
I see an error , warning message on top
Notice a table with chi square and new values of a and k after each iteration.
Program reports, the fitting process converged after a few iterations.

It is 8 iteractions.

Many fitting parameters are reported in the output.

Program reports, final sum of square of residuals.

Notice, relative change in values after the last iteration.

The number is very small

Degrees of freedom is 9
The root mean square or RMS is around 0.17
Updated values of a and k and their error in estimation is also shown.
The correlation matrix of variables is at the end of the output.
Now we have a function that fits the given data points.
Let's plot the data points and function together.
Then, we can see, how well the equation fit the given points.

I will clear the screen with command control l for clarity in video again.

plot f(x) lw 2 title 'fitted data', "error-bar-fitting.txt" using 1:2:3 with yerrorbars pt 7 ps 1.5 notitle Then, enter the plot command as seen on the screen.
I will modify to change legend as fitted data for f of x.

It is represented by a line with width 2.

I have specified no legend title for the starting data set.

Data points are represented only by symbols with error bar and have no line. I have specified a filled circle symbol and 1.5 for point size

set xrange [0.95:5.05] Please pause video as necessary to practice.

Let's also set x axis limits with set xrange command as seen in the video.

replot Replot to see the results.
Slide Number 6

Summary

Now let’s summarize.

In this tutorial, we learned to

  • Display error bars in a graph
  • Fit a given set of data points to an equation
    and
  • Display fitted curve along with parent data


Slide Number 7

Assignment

For assignment activity, please do the following.

For data file assignment.txt, plot x and y error bars in graph. The file is provided to you along with the tutorial. Fit the data to a double exponential decay curve.

Slide Number 8

Spoken Tutorial Project

This video summarises the Spoken Tutorial Project

Please download and watch it.

Slide Number 9

Spoken Tutorial workshops

We conduct workshops and give certificates.

Please write to us.

Slide Number 10

Forum for specific questions:

Post your timed queries in the forum.
Slide Number 11

Acknowledgement

Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
Thank you for joining.

Contributors and Content Editors

Madhurig, Ranipv076, Snehalathak