Difference between revisions of "Gnuplot/C2/Error-bars-and-data-fitting/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "'''Title of script''': '''Error bars and <span style="color:#000000;">D</span><span style="color:#000000;">ata fitting'''</span> '''Author: '''Rani Parvathy '''Keywords:'''...")
 
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''Title of script''': '''Error bars and <span style="color:#000000;">D</span><span style="color:#000000;">ata fitting'''</span>
 
  
'''Author: '''Rani Parvathy
+
{| border=1
 +
|| '''Visual Cue'''
 +
|| '''Narration'''
  
'''Keywords:''' gnuplot, video tutorial, spoken tutorial, data fitting, regression, error bars
+
|-
 +
|| '''Slide Number 1'''
 +
'''Title Slide '''
 +
|| Welcome to the tutorial on
 +
'''Error bars and data fitting '''in '''gnuplot'''.
  
 +
|-
 +
|| '''Slide Number 2'''
 +
'''Learning Objectives'''
 +
|| In this tutorial, we will,
 +
* Learn to add error bars in a plot
 +
* Learn about data fitting
 +
* Write an equation to fit the data
 +
* Make initial guess for value of the coefficients
  
{| style="border-spacing:0;width:6.8472in;"
 
 
|-
 
|-
! align=center style="background-color:#993366;border-top:1pt solid #000000;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | Visual Cue
+
|| '''Slide Number 3'''
! align=center style="background-color:#993366;border:1pt solid #000000;padding:0.0382in;" | Narration
+
'''Learning Objectives'''
 +
||
 +
* Fit the dataset to the equation
 +
* Draw an arrow object in the graph
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 1'''</div>
+
|| '''Slide Number 4'''
 +
'''System and Software Requirement'''
 +
|| To record this tutorial, I am using,
 +
* '''Ubuntu Linux''' 16.04 OS
 +
* '''Gnuplot''' version 5.2.6 and
 +
* '''Gedit''' version 3.18
  
<div style="color:#000000;">'''Title Slide '''</div>
+
|-
 +
|| '''Slide Number 5'''
 +
'''Pre-requisites'''
 +
[https://spoken-tutorials.org https://spoken-tutorials.org]
 +
|| To follow this tutorial,
 +
* Learner must be familiar with the basics of '''gnuplot'''.
 +
* For the prerequisite tutorials, please visit this site.
  
 +
|-
 +
|| '''Slide Number 6'''
 +
'''Code files'''
 +
||
 +
* The files used in this tutorial are provided in the '''code files''' link.
 +
* Please download and extract the files.
  
<div style="color:#000000;">'''Data fitting and error bars'''</div>
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Welcome to the tutorial on </div>
 
 
<div style="color:#000000;">'''Data fitting and error bars'''</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 2'''</div>
+
|| Go to '''Desktop'''.
 +
|| Go to '''Desktop'''.
  
<div style="color:#000000;">'''Learning Objectives'''</div>
+
I have a, '''x,''' '''y,''' '''y'''-error type data, in a text file.
  
 +
|-
 +
|| Hover mouse over '''x''', '''y''' and '''dy''' columns on the screen for the file.
 +
|| The first column is x data.
  
 +
The second column is '''y''' data.
  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">In this tutorial, we will learn,</div>
+
The third column is error in the '''y''' data.
  
 +
|-
 +
|| Close '''gedit'''.
 +
Press '''Ctrl+Alt+T'''.
 +
||
  
* <div style="color:#000000;">Learn to add error bars in a graph</div>
+
Open a '''terminal'''.
* <div style="color:#000000;">Learn data fitting</div>
+
* <div style="color:#000000;">Fit a given dataset to an equation </div>
+
* <div style="color:#000000;">Run non-linear regression and generate fitting parameters</div>
+
  
 +
|-
 +
|| Enter the command '''cd Desktop '''.
 +
Enter the command '''gnuplot'''.
 +
|| Change the directory to '''Desktop''' and open '''gnuplot'''.
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 3'''</div>
+
|| Press '''Ctrl+L'''.
 +
|| I will clear the screen.
  
<div style="color:#000000;">'''System and Software Requirement'''</div>
+
|-
 +
|| Cursor on the '''terminal'''.
 +
|| Let's plot the data to see the trend.
  
 +
|-
 +
|| Enter the command '''plot 'xydy.txt' using 1:2:3 with yerrorbars''' .
 +
|| Enter the '''plot''' command as seen on the screen.
  
<div style="color:#000000;"></div>
+
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Debian Linux</div>
+
|| Hover mouse over ''':3''' .
 +
|| The command, colon 3 with y error bars adds the error to the plot.
  
 +
|-
 +
|| Hover mouse over '''yerrorbars'''.
 +
|| If error limits are on the '''x''' data, we have to use, '''xerrorbars''' term for plotting.
  
<div style="color:#000000;">Gedit 3.22.0</div>
+
The graphic window opens.
  
<div style="color:#000000;">and</div>
+
|-
 +
|| Hover mouse over decay curve.
 +
|| Let's fit this graph to an equation.
  
<div style="color:#000000;">Have Gnuplot 5.2.5 installed</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 4'''</div>
+
|| Cursor on the graph.
 +
|| Here, the data points are likely to follow an exponential decay.
  
<div style="color:#000000;">'''Samson Microphone'''</div>
+
|-
 +
|| Hover mouse on the graph.
 +
|| The points deviate from an accurate exponential decay.
  
 +
This could be due to measurement errors.
  
 +
|-
 +
|| Point mouse next to data.
 +
|| We will fit the given data points to an '''exponential decay''' function.
  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">To record audio, I am using '''Samson''' '''USB''' portable microphone was used.</div>
+
|-
 +
|| Cursor on the screen.
 +
|| Let's see a few steps involved in fitting data points to an equation.
  
 +
|-
 +
|| '''Slide Number 7'''
 +
'''Steps for Fitting Data'''
 +
||
 +
* Define an equation to represent the data.
 +
* Make initial guess values for the coefficients in the equation.
 +
* Optimal values for the coefficients are found by an iterative process.
  
<div style="color:#000000;">The model number '''SAGOMIC'''</div>
+
|-
 +
|| '''Slide Number 8'''
  
 +
'''Steps for Fitting Data'''
 +
||
 +
* Check for goodness of the fit
 +
* A good fitting is measured by a low value of chi square and
 +
* Display the fitted data with the starting dataset
  
<div style="color:#000000;">I bought it from '''amazon''' website, for about rupees four thousand</div>
+
|-
 +
|| Type, '''f(x) = a * exp(-k*x)'''  
 +
and press '''Enter'''.
 +
|| First, let's define the function.
  
 +
In the '''gnuplot''' prompt, type f of x is equal to a times e to the power minus k x.
  
<div style="color:#000000;"><span style="background-color:transparent;">It may be available in other websites.</span></div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 5'''</div>
+
|| Go to graphical window.
 +
|| Make an educated initial guess for the values of '''a''' and '''k'''.
  
<div style="color:#000000;">'''Pre-requisites'''</div>
+
Go to the graphical window.
  
 +
|-
 +
|| Hover mouse near top of y axis.
 +
|| From the graph, I will place the initial value of '''a''' at '''1,50,000'''.
  
<div style="color:#000000;"></div>
+
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">To follow this tutorial, learner’s must be familiar with, </div>
+
|| Hover mouse to show ½ decay.
 +
|| For an exponential decay, I will place the initial guess of '''k''' around '''0.5''' .
  
 +
|-
 +
|| Close the graphical window.
 +
|| Close the graphical window and go to the '''gnuplot terminal''' prompt.
  
<div style="color:#000000;">Basic computer and internet skills</div>
+
|-
 
+
|| Enter the commands,
 +
'''a=150000 '''
 +
'''k=0.5'''
 +
|| Enter commands to set initial guess values.
  
<div style="color:#000000;">Concept of graphing </div>
+
Set '''a''' to 150 thousand and '''k''' to 0.5 .
  
<div style="color:#000000;">and </div>
 
 
<div style="color:#000000;">College level Mathematics skills</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 6'''</div>
+
|| Type, '''fit f(x) ‘xydy.txt’ using 1:2:3 via a,k'''
 +
and press '''Enter'''.
 +
|| To fit the data type the command,
  
<div style="color:#000000;">'''Pre-requisites'''</div>
+
'''fit f of x''' in single quotes the file name.
  
 +
Here it is '''xydy dot txt'''.
  
<div style="color:#000000;"></div>
+
Then '''using 1 colon 2 colon 3''' via a comma k .
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <span style="background-color:transparent;color:#000000;">Please locate this tutorial on our web page, </span><span style="background-color:transparent;color:#000000;">'''spoken hyphen tutorial dot org'''</span><span style="background-color:transparent;color:#000000;"> </span>
+
  
 +
Here '''a''' and '''k''' are the '''coefficients'''.
  
<div style="color:#000000;">Prerequisite '''spoken''' '''tutorials''', if any, will be mentioned in this page </div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | Go to '''Desktop'''.
+
|| Hover mouse over ''':3''' .
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">First, we will first learn to incorporate error bars in a graph.</div>
+
|| We could leave out the colon 3 part in the command.  
 +
Then, errors in the '''y''' data are not considered during the data fitting process.
  
 +
|-
 +
|| Press '''Enter'''.
 +
Data fitting is seen on the screen.
 +
|| Press '''Enter''' to run the data fitting algorithm.
  
<div style="color:#000000;">First, Go to '''Desktop'''.</div>
+
The coefficients in the equation are optimized by an iterative process.
 +
 +
The output is generated on the screen.
  
 +
|-
 +
|| Scroll up.
 +
|| Let's scroll up the screen.
  
<div style="color:#000000;">I have a, x y yerror type data, in a text file. </div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | Double click to open the file.
+
||  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">It is saved in '''Desktop''' directory for me. </div>
+
|| I see an error warning message on the top.
  
 +
|-
 +
|| Hover mouse over the '''chi square''' table.
 +
|| Notice a table with '''chi square''' and new values for '''a''' and '''k''' after each iteration.
  
<div style="color:#000000;">Double click on the file icon to open it in a text editor.</div>
+
|-
 
+
|| Incorporate the number of iterations.
 
+
|| The program reports that, the fitting process converged after 10 iterations.
<div style="color:#000000;">The file opens in gedit for me.</div>
+
  
 +
|-
 +
|| Hover mouse over '''final sum of square of residuals'''.
 +
|| Many fitting parameters are reported in the output.
 +
Program reports, final sum of square of residuals.
  
<div style="color:#000000;">This file is provided to you with the tutorial.</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
|| Hover mouse over iteration value.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | The first column is '''x''' data.
+
|| Notice, relative change in values after the last iteration.
  
  
Second column is '''y''' data.
+
The number is very small.
  
 
The third column is '''y''' data error bar in measurement.
 
|-
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | Close '''gedit'''
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Close '''gedit''' by clicking on the x-sign.
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">Press '''ctrl alt t'''</div>
+
|| Hover mouse over '''Degrees of freedom'''.
 +
|| '''Degrees of freedom''' is 9.
  
 
<div style="color:#000000;">'''cd ~/Desktop'''</div>
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Press '''ctrl alt t''' keys together to open a '''terminal'''.
 
 
 
Change directory to '''Desktop''' as seen on the screen.
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">ctrl+alt+T</div>
+
|| Hover mouse over '''RMS'''.
 +
|| '''RMS''' of residuals is around 2.5.
  
<div style="color:#000000;">>'''gnuplot'''</div>
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Open '''gnuplot'''.
 
 
 
Type '''gnuplot''' and '''enter'''
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | Show qt on screen.
+
|| Show '''a''' and '''k''' values on the screen.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">'''Set''' '''terminal''' as necessary. </div>
+
|| Updated values of '''a''' and '''k''' and their error in estimation is also shown.
  
 
<div style="color:#000000;">For me it is already in '''qt'''.</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | '''Ctrl-l'''
+
|| Hover mouse over the '''correlation matrix'''.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | I will clear screen with command control l.
+
|| The '''correlation matrix''' of variables is at the end of the output.
  
This takes terminal prompt to top of the screen for clarity in video.
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |  
+
|| Cursor on the '''terminal'''.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | First, let's plot the data to see the trend and for visual inspection.
+
|| Now we have a function that fits the given data points.
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | '''plot 'error-bar.txt' using 1:2:3 with yerrorbars'''
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Enter the plot command as seen on the screen.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | If error limits are on the x data, we can use, x error bars term for plotting.
+
  
 +
Let's plot the data points and the function together.
  
The graphic window opens.
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
|| Press '''Ctrl+L''' .
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | The colon 3 with y error bars in the plot command adds the error to the plot.
+
|| I will clear the screen.
|-
+
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | Hover mouse over decay curve.
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Next, let's fit this graph to an equation.  
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | This data likely represent an exponential decay.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | The points may be off the ideal curve due to measurement errors.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | We will fit the given data points to an exponential decay function.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Let's see a few steps involved in fitting data points to an equation.
+
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <span style="color:#000000;">'''Slide Number </span><span style="color:#000000;">7'''</span>
+
|| Enter the command, '''plot f(x) lw 2 title 'fitted data', "xydy.txt" using 1:2:3 with yerrorbars pt 7 ps 1.5 notitle''' .
 +
|| Enter the command as seen on the screen.
  
'''Steps in data fitting'''
+
This plots the data and the function together.
  
 +
We are plotting the fitted equation along with the initial data points.
  
Find a function to represent the data
+
|-
 +
|| Hover mouse near the legend.
 +
|| The fitted data is represented by a line with a line.
  
Initial guess values for constants
+
I am specifying the legend for '''f of x''' as '''fitted data'''.
  
 +
No legend title is added for the starting dataset as no '''notitle''' is mentioned.
  
A good fitting, measured by chi square
+
I have specified a filled circle '''symbol''' and 1.5 for point size.
  
 +
|-
 +
|| Show the line on the graphics window.
 +
Show symbol with error bar.
 +
|| Data points are represented by symbols with '''error bar''' and without a line style.
  
Find the 'optimal' value of the constants in the function
+
|-
 +
|| Enter the command, '''set xrange [0.95:5.05]''' .
 +
|| Let's also set '''x axis''' limits with '''set xrange''' command as seen.
  
 +
|-
 +
|| Type '''replot''' and press '''Enter''' to see the graphics window.
 +
|| '''Replot''' to see the results.
  
<div style="color:#000000;">Display the fitted data</div>
+
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | First, define a function to represent the data
+
|| Show this web site address screen shot.
 +
'''http://gnuplot.sourceforge.net/demo/fit.html'''
 +
|| Check the '''gnuplot''' website for example '''scripts''' on data fitting.
  
 +
|-
 +
|| Cursor on the screen, around the (1.3,6000) region.
 +
|| Next, let’s draw an arrow object in the graph.
  
Make initial guess values for constants
+
|-
 +
|| Move the mouse on the screen to show the arrow placement around ('''1.63,77200 to 1.7, 62000''').
 +
|| In the graph, I want to add an arrow.
  
 +
|-
 +
|| Highlight in video, the co-ordinates seen on the graph window.
 +
('''1.63,77200 to 1.7, 62000''').
 +
|| I will note down the coordinates as seen in the graphics window.
  
A good fitting, measured by '''chi square''' value
+
|-
 +
|| Go to the '''terminal'''.
 +
|| Go to the '''terminal'''.
  
 +
|-
 +
|| Type, '''set arrow 1 from 1.63,77200 to 1.7, 62000''' and press '''Enter'''.
 +
|| Enter the commands as seen on the screen.
 +
Here, '''one '''is the name I have given for the arrow object.
  
Find the 'optimal' value of the constants in the function
 
 
 
and Display the fitted data
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | '''f(x) = a * exp(-k*x)'''
+
|| Type '''replot''' and press '''Enter'''.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">First, let's define the function.</div>
+
|| '''Replot''' to see the updated result.
  
 
<div style="color:#000000;">Type '''f''' of '''x''' is equal to a times '''e''' to the power minus '''k x'''</div>
 
 
 
<div style="color:#000000;">Use the syntax as seen on the screen</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | Go to graphical window.
+
|| Cursor on the graphics window.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Let's make an educated initial guess for the initial guess values of a and k</div>
+
|| I will also add a second arrow in another direction.
  
 
<div style="color:#000000;">Go to graphical window.</div>
 
|-
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" | From the graph, I will place the initial value of a at one lakh fitfty thousand
 
|-
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" | For an exponential decay, I will place the initial guess of k around 0.5
 
|-
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Close the graphical window and go to gnuplot terminal prompt.
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''a=150000 '''</div>
+
|| Type,
 +
'''set arrow 2 from 1.63,77200 to 1.4, 62000''' and press '''Enter'''.
 +
|| Go to the '''terminal''' and enter the command as seen on the screen.
 +
I will name this arrow as '''two'''.
  
<div style="color:#000000;">'''k=0.5'''</div>
 
 
 
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Enter commands to set the values of a and k</div>
 
 
<div style="color:#000000;">Enter a equal to fifteen hundred thousand</div>
 
 
<div style="color:#000000;">Enter k equal to zero point five</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | '''fit f(x) “error-bar.txt” using 1:2:3 via a,k'''
+
|| Type '''replot''' and press '''Enter'''.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">To fit the data use command as seen on the screen.</div>
+
|| '''Replot''' to see the updated result.
  
 
<div style="color:#000000;">Fit space f of x space in double quotes error hyphen bar dot txt. </div>
 
 
 
<div style="color:#000000;">Then Space using space 1 colon 2 colon 3 via a comma k</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |  
+
|| Cursor on the graphics window.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | If column 3 is not mentioned, the y axis uncertainties is not considered for data fitting.
+
|| Now we see two arrows in the graphics window.
|-
+
I want to remove one of the arrows.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
To remove the object, we have to '''unset''' the object.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | The software does the fitting and gives output values.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" | Let's scroll up the screen.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" | I see an error , warning message on top
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" | Notice a table with chi square and new values of a and k after each iteration.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Program reports, the fitting process converged after a few iterations.</div>
+
 
+
  
<div style="color:#000000;">It is 8 iteractions.</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |  
+
|| Type '''unset arrow first''' and press '''Enter'''.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Many fitting parameters are reported in the output.</div>
+
|| Hence, go to the '''terminal'''.
 +
Enter the command, '''unset space arrow space one''' to remove the first arrow.
  
 
<div style="color:#000000;">Program reports, final sum of square of residuals.</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
|| Type '''replot''' and press '''Enter'''.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Notice, relative change in values after the last iteration.</div>
+
|| '''Replot''' to see the updated result.
  
 
<div style="color:#000000;">The number is very small</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |  
+
|| Cursor on the graphics window.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" | Degrees of freedom is 9
+
|| The arrow that was named '''one''' is now removed from the graphics window,
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" | The root mean square or RMS is around 0.17
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Updated values of a and k and their error in estimation is also shown.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | The correlation matrix of variables is at the end of the output.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Now we have a function that fits the given data points.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Let's plot the data points and function together.
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Then, we can see, how well the equation fit the given points.</div>
+
 
+
  
<div style="color:#000000;">I will clear the screen with command control l for clarity in video again.</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | '''plot f(x) lw 2 title 'fitted data', "error-bar-fitting.txt" using 1:2:3 with yerrorbars pt 7 ps 1.5 notitle'''
+
|| Close the graphics window.
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Then, enter the plot command as seen on the screen.</div>
+
Type '''quit''' and press '''Enter'''.
 
+
|| Close the graphics window and '''quit gnuplot'''.
 
+
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |  
+
|| '''Slide Number 9'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">I will modify to change legend as '''fitted data''' for f of x.</div>
+
'''Summary'''
 
+
|| To summarize, in this tutorial, we
 +
* Incorporated error bars in a plot graph
 +
* Fitted a given set of data points to an equation
 +
* Plotted the fitted curve along with parent data
 +
* Added and removed an arrow object
  
<div style="color:#000000;">It is represented by a line with width 2.</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |  
+
|| '''Slide Number 10'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">I have specified no legend title for the starting data set.</div>
+
'''Assignment'''
 +
|| For the assignment activity, please do the following.
 +
* For the data file '''assignment.txt''', make an xy graph with ''xyerrorbars''.
 +
* This file is available in the Code files link.
  
 
<div style="color:#000000;">Data points are represented only by symbols with error bar and have no line.</div>
 
 
 
<div style="color:#000000;">I have specified a filled circle symbol and 1.5 for point size</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | '''set xrange [0.95:5.05]'''
+
|| '''Slide Number 11'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Please pause video as necessary to practice.</div>
+
'''Assignment'''
 +
||  
 +
* Fit the data to a double exponential decay curve with ''yerrorbars''.
 +
* Plot the fitted data
 +
* Draw an arrow object in the graph at the position of your choice.
  
 
Let's also set x axis limits with set xrange command as seen in the video.
 
|-
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | '''replot'''
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | Replot to see the results.
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 8'''</div>
+
|| Glimpse of assignment
 
+
|| The completed assignment looks similar to this.
<div style="color:#000000;">'''Summary'''</div>
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | 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<br/>and
+
* Display fitted curve along with parent data
+
 
+
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 9'''</div>
+
|| '''Slide Number 12'''
 +
'''Spoken Tutorial Project'''
 +
|| This video summarises the '''Spoken Tutorial''' Project .
 +
Please download and watch it.
  
<div style="color:#000000;">'''Assignment'''</div>
 
 
 
<div style="color:#000000;"></div>
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">For assignment activity, please do the following.</div>
 
 
 
<div style="color:#000000;">For data file assignment.txt, plot x and y error bars in graph.</div>
 
 
 
<div style="color:#000000;">The file is provided to you along with the tutorial.</div>
 
 
 
<div style="color:#000000;">Fit the data to a double exponential decay curve.</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 10'''</div>
+
|| '''Slide Number 13'''
 +
'''Spoken Tutorial workshops'''
 +
|| We conduct workshops and give certificates.
  
<div style="color:#000000;">'''Spoken Tutorial Project'''</div>
+
For more details, please write to us.
  
 
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <span style="color:#000000;">This video summarises the</span><span style="color:#000000;"> Spoken Tutorial Project </span>
 
 
 
<div style="color:#000000;">If you do not have good bandwidth, you may download and watch it.</div>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 11'''</div>
+
|| '''Slide Number 14'''
  
<div style="color:#000000;">'''Spoken Tutorial workshops'''</div>
+
'''Forum for specific questions:'''
 +
|| Post your timed queries in the forum.
  
 
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <span style="color:#000000;">We</span><span style="color:#000000;"> conduct workshops using spoken tutorials and give certificates. </span>
 
 
 
<span style="color:#000000;">P</span><span style="color:#000000;">lease write to us.</span>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 12'''</div>
+
|| '''Slide Number 15'''
 +
'''Acknowledgement'''
 +
|| Spoken Tutorial Project is funded by '''MHRD''', '''Government of India'''.
  
<div style="color:#000000;">'''Forum for specific questions:'''</div>
 
 
 
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" | Post your timed queries in the forum.
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;" | <div style="color:#000000;">'''Slide Number 13'''</div>
+
||  
 +
|| This is Rani, from '''IIT''', '''Bombay'''.
 +
Thank you for joining.
  
<span style="color:#000000;">'''Acknowledgemen'''</span><span style="color:#000000;">t</span>
 
 
 
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.</div>
 
 
 
 
|-
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" |
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" | Thank you for joining.
 
|-
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.0382in;color:#000000;" | '''plot f(x) lw 2, "error-bar-fitting.txt" using 1:2:3 with yerrorbars pt 7 ps 1.5'''
 
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.0382in;color:#000000;" |
 
 
|-
 
|-
 
|}
 
|}
<div style="color:#000000;margin-left:0in;margin-right:0in;"></div>
 

Latest revision as of 09:51, 4 February 2020

Visual Cue Narration
Slide Number 1

Title Slide

Welcome to the tutorial on

Error bars and data fitting in gnuplot.

Slide Number 2

Learning Objectives

In this tutorial, we will,
  • Learn to add error bars in a plot
  • Learn about data fitting
  • Write an equation to fit the data
  • Make initial guess for value of the coefficients
Slide Number 3

Learning Objectives

  • Fit the dataset to the equation
  • Draw an arrow object in the graph
Slide Number 4

System and Software Requirement

To record this tutorial, I am using,
  • Ubuntu Linux 16.04 OS
  • Gnuplot version 5.2.6 and
  • Gedit version 3.18
Slide Number 5

Pre-requisites https://spoken-tutorials.org

To follow this tutorial,
  • Learner must be familiar with the basics of gnuplot.
  • For the prerequisite tutorials, please visit this site.
Slide Number 6

Code files

  • The files used in this tutorial are provided in the code files link.
  • Please download and extract the files.
Go to Desktop. Go to Desktop.

I have a, x, y, y-error type data, in a text file.

Hover mouse over x, y and dy columns on the screen for the file. The first column is x data.

The second column is y data.

The third column is error in the y data.

Close gedit.

Press Ctrl+Alt+T.

Open a terminal.

Enter the command cd Desktop .

Enter the command gnuplot.

Change the directory to Desktop and open gnuplot.
Press Ctrl+L. I will clear the screen.
Cursor on the terminal. Let's plot the data to see the trend.
Enter the command plot 'xydy.txt' using 1:2:3 with yerrorbars . Enter the plot command as seen on the screen.
Hover mouse over :3 . The command, colon 3 with y error bars adds the error to the plot.
Hover mouse over yerrorbars. If error limits are on the x data, we have to use, xerrorbars term for plotting.

The graphic window opens.

Hover mouse over decay curve. Let's fit this graph to an equation.
Cursor on the graph. Here, the data points are likely to follow an exponential decay.
Hover mouse on the graph. The points deviate from an accurate exponential decay.

This could be due to measurement errors.

Point mouse next to data. We will fit the given data points to an exponential decay function.
Cursor on the screen. Let's see a few steps involved in fitting data points to an equation.
Slide Number 7

Steps for Fitting Data

  • Define an equation to represent the data.
  • Make initial guess values for the coefficients in the equation.
  • Optimal values for the coefficients are found by an iterative process.
Slide Number 8

Steps for Fitting Data

  • Check for goodness of the fit
  • A good fitting is measured by a low value of chi square and
  • Display the fitted data with the starting dataset
Type, f(x) = a * exp(-k*x)

and press Enter.

First, let's define the function.

In the gnuplot prompt, type f of x is equal to a times e to the power minus k x.

Go to graphical window. Make an educated initial guess for the values of a and k.

Go to the graphical window.

Hover mouse near top of y axis. From the graph, I will place the initial value of a at 1,50,000.
Hover mouse to show ½ decay. For an exponential decay, I will place the initial guess of k around 0.5 .
Close the graphical window. Close the graphical window and go to the gnuplot terminal prompt.
Enter the commands,

a=150000 k=0.5

Enter commands to set initial guess values.

Set a to 150 thousand and k to 0.5 .

Type, fit f(x) ‘xydy.txt’ using 1:2:3 via a,k

and press Enter.

To fit the data type the command,

fit f of x in single quotes the file name.

Here it is xydy dot txt.

Then using 1 colon 2 colon 3 via a comma k .

Here a and k are the coefficients.

Hover mouse over :3 . We could leave out the colon 3 part in the command.

Then, errors in the y data are not considered during the data fitting process.

Press Enter.

Data fitting is seen on the screen.

Press Enter to run the data fitting algorithm.

The coefficients in the equation are optimized by an iterative process.

The output is generated on the screen.

Scroll up. Let's scroll up the screen.
I see an error warning message on the top.
Hover mouse over the chi square table. Notice a table with chi square and new values for a and k after each iteration.
Incorporate the number of iterations. The program reports that, the fitting process converged after 10 iterations.
Hover mouse over final sum of square of residuals. Many fitting parameters are reported in the output.

Program reports, final sum of square of residuals.

Hover mouse over iteration value. Notice, relative change in values after the last iteration.


The number is very small.

Hover mouse over Degrees of freedom. Degrees of freedom is 9.
Hover mouse over RMS. RMS of residuals is around 2.5.
Show a and k values on the screen. Updated values of a and k and their error in estimation is also shown.
Hover mouse over the correlation matrix. The correlation matrix of variables is at the end of the output.
Cursor on the terminal. Now we have a function that fits the given data points.

Let's plot the data points and the function together.

Press Ctrl+L . I will clear the screen.
Enter the command, plot f(x) lw 2 title 'fitted data', "xydy.txt" using 1:2:3 with yerrorbars pt 7 ps 1.5 notitle . Enter the command as seen on the screen.

This plots the data and the function together.

We are plotting the fitted equation along with the initial data points.

Hover mouse near the legend. The fitted data is represented by a line with a line.

I am specifying the legend for f of x as fitted data.

No legend title is added for the starting dataset as no notitle is mentioned.

I have specified a filled circle symbol and 1.5 for point size.

Show the line on the graphics window.

Show symbol with error bar.

Data points are represented by symbols with error bar and without a line style.
Enter the command, set xrange [0.95:5.05] . Let's also set x axis limits with set xrange command as seen.
Type replot and press Enter to see the graphics window. Replot to see the results.
Show this web site address screen shot.

http://gnuplot.sourceforge.net/demo/fit.html

Check the gnuplot website for example scripts on data fitting.
Cursor on the screen, around the (1.3,6000) region. Next, let’s draw an arrow object in the graph.
Move the mouse on the screen to show the arrow placement around (1.63,77200 to 1.7, 62000). In the graph, I want to add an arrow.
Highlight in video, the co-ordinates seen on the graph window.

(1.63,77200 to 1.7, 62000).

I will note down the coordinates as seen in the graphics window.
Go to the terminal. Go to the terminal.
Type, set arrow 1 from 1.63,77200 to 1.7, 62000 and press Enter. Enter the commands as seen on the screen.

Here, one is the name I have given for the arrow object.

Type replot and press Enter. Replot to see the updated result.
Cursor on the graphics window. I will also add a second arrow in another direction.
Type,

set arrow 2 from 1.63,77200 to 1.4, 62000 and press Enter.

Go to the terminal and enter the command as seen on the screen.

I will name this arrow as two.

Type replot and press Enter. Replot to see the updated result.
Cursor on the graphics window. Now we see two arrows in the graphics window.

I want to remove one of the arrows. To remove the object, we have to unset the object.

Type unset arrow first and press Enter. Hence, go to the terminal.

Enter the command, unset space arrow space one to remove the first arrow.

Type replot and press Enter. Replot to see the updated result.
Cursor on the graphics window. The arrow that was named one is now removed from the graphics window,
Close the graphics window.

Type quit and press Enter.

Close the graphics window and quit gnuplot.
Slide Number 9

Summary

To summarize, in this tutorial, we
  • Incorporated error bars in a plot graph
  • Fitted a given set of data points to an equation
  • Plotted the fitted curve along with parent data
  • Added and removed an arrow object
Slide Number 10

Assignment

For the assignment activity, please do the following.
  • For the data file assignment.txt, make an xy graph with xyerrorbars.
  • This file is available in the Code files link.
Slide Number 11

Assignment

  • Fit the data to a double exponential decay curve with yerrorbars.
  • Plot the fitted data
  • Draw an arrow object in the graph at the position of your choice.
Glimpse of assignment The completed assignment looks similar to this.
Slide Number 12

Spoken Tutorial Project

This video summarises the Spoken Tutorial Project .

Please download and watch it.

Slide Number 13

Spoken Tutorial workshops

We conduct workshops and give certificates.

For more details, please write to us.

Slide Number 14

Forum for specific questions:

Post your timed queries in the forum.
Slide Number 15

Acknowledgement

Spoken Tutorial Project is funded by MHRD, Government of India.
This is Rani, from IIT, Bombay.

Thank you for joining.

Contributors and Content Editors

Madhurig, Ranipv076, Snehalathak