Difference between revisions of "Gnuplot/C2/Error-bars-and-data-fitting/English"
Snehalathak (Talk | contribs) |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
'''Title Slide ''' | '''Title Slide ''' | ||
|| Welcome to the tutorial on | || Welcome to the tutorial on | ||
− | '''Error bars and data fitting '''in gnuplot. | + | '''Error bars and data fitting '''in '''gnuplot'''. |
|- | |- | ||
Line 18: | Line 18: | ||
* Write an equation to fit the data | * Write an equation to fit the data | ||
* Make initial guess for value of the coefficients | * Make initial guess for value of the coefficients | ||
+ | |||
+ | |- | ||
+ | || '''Slide Number 3''' | ||
+ | '''Learning Objectives''' | ||
+ | || | ||
* Fit the dataset to the equation | * Fit the dataset to the equation | ||
* Draw an arrow object in the graph | * Draw an arrow object in the graph | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 4''' |
'''System and Software Requirement''' | '''System and Software Requirement''' | ||
|| To record this tutorial, I am using, | || To record this tutorial, I am using, | ||
− | * '''Ubuntu Linux''' 16.04 | + | * '''Ubuntu Linux''' 16.04 OS |
− | * '''Gnuplot''' 5.2.6 and | + | * '''Gnuplot''' version 5.2.6 and |
− | * '''Gedit''' 3.18 | + | * '''Gedit''' version 3.18 |
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 5''' |
'''Pre-requisites''' | '''Pre-requisites''' | ||
[https://spoken-tutorials.org https://spoken-tutorials.org] | [https://spoken-tutorials.org https://spoken-tutorials.org] | ||
− | || To follow this tutorial, * Learner must be familiar with the basics of '''gnuplot'''. | + | || To follow this tutorial, |
+ | * Learner must be familiar with the basics of '''gnuplot'''. | ||
* For the prerequisite tutorials, please visit this site. | * For the prerequisite tutorials, please visit this site. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 6''' |
'''Code files''' | '''Code files''' | ||
− | || The | + | || |
− | Please download and extract the 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'''. | ||
|| Go to '''Desktop'''. | || Go to '''Desktop'''. | ||
+ | |||
I have a, '''x,''' '''y,''' '''y'''-error type data, in a text file. | I have a, '''x,''' '''y,''' '''y'''-error type data, in a text file. | ||
Line 50: | Line 58: | ||
|| Hover mouse over '''x''', '''y''' and '''dy''' columns on the screen for the file. | || Hover mouse over '''x''', '''y''' and '''dy''' columns on the screen for the file. | ||
|| The first column is x data. | || The first column is x data. | ||
+ | |||
The second column is '''y''' data. | The second column is '''y''' data. | ||
+ | |||
The third column is error in the '''y''' data. | The third column is error in the '''y''' data. | ||
Line 56: | Line 66: | ||
|| Close '''gedit'''. | || Close '''gedit'''. | ||
Press '''Ctrl+Alt+T'''. | Press '''Ctrl+Alt+T'''. | ||
− | || | + | || |
+ | |||
Open a '''terminal'''. | Open a '''terminal'''. | ||
Line 73: | Line 84: | ||
|- | |- | ||
− | || Enter the command '''plot ' | + | || Enter the command '''plot 'xydy.txt' using 1:2:3 with yerrorbars''' . |
|| Enter the '''plot''' command as seen on the screen. | || Enter the '''plot''' command as seen on the screen. | ||
Line 82: | Line 93: | ||
|- | |- | ||
|| Hover mouse over '''yerrorbars'''. | || Hover mouse over '''yerrorbars'''. | ||
− | || If error limits are on the '''x''' data, we have to use, ''' | + | || If error limits are on the '''x''' data, we have to use, '''xerrorbars''' term for plotting. |
+ | |||
The graphic window opens. | The graphic window opens. | ||
Line 95: | Line 107: | ||
|- | |- | ||
|| Hover mouse on the graph. | || Hover mouse on the graph. | ||
− | || The points | + | || The points deviate from an accurate exponential decay. |
+ | |||
This could be due to measurement errors. | This could be due to measurement errors. | ||
Line 104: | Line 117: | ||
|- | |- | ||
|| Cursor on the screen. | || Cursor on the screen. | ||
− | || Let's see a few steps involved in fitting data points | + | || Let's see a few steps involved in fitting data points to an equation. |
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 7''' |
'''Steps for Fitting Data''' | '''Steps for Fitting Data''' | ||
|| | || | ||
* Define an equation to represent the data. | * Define an equation to represent the data. | ||
* Make initial guess values for the coefficients in the equation. | * Make initial guess values for the coefficients in the equation. | ||
− | * Optimal values for the coefficients | + | * Optimal values for the coefficients are found by an iterative process. |
− | + | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 8''' |
'''Steps for Fitting Data''' | '''Steps for Fitting Data''' | ||
|| | || | ||
* Check for goodness of the fit | * Check for goodness of the fit | ||
− | * A good fitting is measured by a low value of chi square | + | * A good fitting is measured by a low value of chi square and |
− | + | * Display the fitted data with the starting dataset | |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 131: | Line 140: | ||
and press '''Enter'''. | and press '''Enter'''. | ||
|| First, let's define the function. | || 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. | In the '''gnuplot''' prompt, type f of x is equal to a times e to the power minus k x. | ||
Line 136: | Line 146: | ||
|| Go to graphical window. | || Go to graphical window. | ||
|| Make an educated initial guess for the values of '''a''' and '''k'''. | || Make an educated initial guess for the values of '''a''' and '''k'''. | ||
+ | |||
Go to the graphical window. | Go to the graphical window. | ||
Line 155: | Line 166: | ||
'''k=0.5''' | '''k=0.5''' | ||
|| Enter commands to set initial guess values. | || Enter commands to set initial guess values. | ||
+ | |||
Set '''a''' to 150 thousand and '''k''' to 0.5 . | Set '''a''' to 150 thousand and '''k''' to 0.5 . | ||
Line 161: | Line 173: | ||
and press '''Enter'''. | and press '''Enter'''. | ||
|| To fit the data type the command, | || To fit the data type the command, | ||
+ | |||
'''fit f of x''' in single quotes the file name. | '''fit f of x''' in single quotes the file name. | ||
− | Here it is ''' | + | |
+ | Here it is '''xydy dot txt'''. | ||
+ | |||
Then '''using 1 colon 2 colon 3''' via a comma k . | Then '''using 1 colon 2 colon 3''' via a comma k . | ||
+ | |||
Here '''a''' and '''k''' are the '''coefficients'''. | Here '''a''' and '''k''' are the '''coefficients'''. | ||
|- | |- | ||
|| Hover mouse over ''':3''' . | || Hover mouse over ''':3''' . | ||
− | || We could leave out the colon 3 in the command. | + | || We could leave out the colon 3 part in the command. |
− | Then, errors in the '''y''' data are not considered during the data fitting | + | Then, errors in the '''y''' data are not considered during the data fitting process. |
− | process. | + | |
|- | |- | ||
Line 176: | Line 191: | ||
Data fitting is seen on the screen. | Data fitting is seen on the screen. | ||
|| Press '''Enter''' to run the data fitting algorithm. | || Press '''Enter''' to run the data fitting algorithm. | ||
− | The coefficients in the equation are optimized by an iterative process. | + | |
+ | The coefficients in the equation are optimized by an iterative process. | ||
+ | |||
The output is generated on the screen. | The output is generated on the screen. | ||
Line 189: | Line 206: | ||
|- | |- | ||
|| Hover mouse over the '''chi square''' table. | || Hover mouse over the '''chi square''' table. | ||
− | || Notice a table with '''chi square''' and new values | + | || Notice a table with '''chi square''' and new values for '''a''' and '''k''' after each iteration. |
|- | |- | ||
Line 213: | Line 230: | ||
|- | |- | ||
|| Hover mouse over '''RMS'''. | || Hover mouse over '''RMS'''. | ||
− | || '''RMS''' of residuals is around | + | || '''RMS''' of residuals is around 2.5. |
|- | |- | ||
Line 226: | Line 243: | ||
|| Cursor on the '''terminal'''. | || Cursor on the '''terminal'''. | ||
|| Now we have a function that fits the given data points. | || Now we have a function that fits the given data points. | ||
− | Let's plot the data points and function together. | + | |
+ | Let's plot the data points and the function together. | ||
|- | |- | ||
Line 234: | Line 252: | ||
|- | |- | ||
|| 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, '''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 | + | || Enter the command as seen on the screen. |
− | We are plotting the fitted equation | + | |
+ | 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. | || Hover mouse near the legend. | ||
|| The fitted data is represented by a line with a line. | || The fitted data is represented by a line with a line. | ||
+ | |||
I am specifying the legend for '''f of x''' as '''fitted data'''. | I am specifying the legend for '''f of x''' as '''fitted data'''. | ||
− | No legend title is added for the starting | + | |
− | mentioned. | + | 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. | ||
|- | |- | ||
Line 248: | Line 272: | ||
Show symbol with error bar. | Show symbol with error bar. | ||
|| Data points are represented by symbols with '''error bar''' and without a line style. | || Data points are represented by symbols with '''error bar''' and without a line style. | ||
− | |||
|- | |- | ||
Line 265: | Line 288: | ||
|- | |- | ||
|| Cursor on the screen, around the (1.3,6000) region. | || 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'''). | || 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 | + | || In the graph, I want to add an arrow. |
|- | |- | ||
Line 298: | Line 320: | ||
'''set arrow 2 from 1.63,77200 to 1.4, 62000''' and press '''Enter'''. | '''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. | || Go to the '''terminal''' and enter the command as seen on the screen. | ||
− | I will name this arrow as ''' | + | I will name this arrow as '''two'''. |
|- | |- | ||
Line 307: | Line 329: | ||
|| Cursor on the graphics window. | || Cursor on the graphics window. | ||
|| Now we see two arrows in 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. | To remove the object, we have to '''unset''' the object. | ||
|- | |- | ||
|| Type '''unset arrow first''' and press '''Enter'''. | || Type '''unset arrow first''' and press '''Enter'''. | ||
− | || | + | || Hence, go to the '''terminal'''. |
− | Enter the command, '''unset arrow | + | Enter the command, '''unset space arrow space one''' to remove the first arrow. |
|- | |- | ||
Line 320: | Line 343: | ||
|- | |- | ||
|| Cursor on the graphics window. | || Cursor on the graphics window. | ||
− | || The arrow that was named ''' | + | || The arrow that was named '''one''' is now removed from the graphics window, |
|- | |- | ||
Line 328: | Line 351: | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 9''' |
'''Summary''' | '''Summary''' | ||
− | || To summarize, in this tutorial, we | + | || To summarize, in this tutorial, we |
* Incorporated error bars in a plot graph | * 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 | * Plotted the fitted curve along with parent data | ||
* Added and removed an arrow object | * Added and removed an arrow object | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 10''' |
− | '''Assignment | + | '''Assignment''' |
|| For the assignment activity, please do the following. | || For the assignment activity, please do the following. | ||
− | * For the data file '''assignment.txt''', make an xy graph with ''xyerrorbars'' | + | * For the data file '''assignment.txt''', make an xy graph with ''xyerrorbars''. |
* This file is available in the Code files link. | * This file is available in the Code files link. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 11''' |
− | '''Assignment | + | '''Assignment''' |
|| | || | ||
* Fit the data to a double exponential decay curve with ''yerrorbars''. | * Fit the data to a double exponential decay curve with ''yerrorbars''. | ||
Line 352: | Line 375: | ||
|- | |- | ||
− | || '''Slide Number | + | || Glimpse of assignment |
+ | || The completed assignment looks similar to this. | ||
+ | |||
+ | |- | ||
+ | || '''Slide Number 12''' | ||
'''Spoken Tutorial Project''' | '''Spoken Tutorial Project''' | ||
|| This video summarises the '''Spoken Tutorial''' Project . | || This video summarises the '''Spoken Tutorial''' Project . | ||
Line 358: | Line 385: | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 13''' |
'''Spoken Tutorial workshops''' | '''Spoken Tutorial workshops''' | ||
|| We conduct workshops and give certificates. | || We conduct workshops and give certificates. | ||
Line 365: | Line 392: | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 14''' |
'''Forum for specific questions:''' | '''Forum for specific questions:''' | ||
Line 371: | Line 398: | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 15''' |
'''Acknowledgement''' | '''Acknowledgement''' | ||
|| Spoken Tutorial Project is funded by '''MHRD''', '''Government of India'''. | || Spoken Tutorial Project is funded by '''MHRD''', '''Government of India'''. |
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,
|
Slide Number 3
Learning Objectives |
|
Slide Number 4
System and Software Requirement |
To record this tutorial, I am using,
|
Slide Number 5
Pre-requisites https://spoken-tutorials.org |
To follow this tutorial,
|
Slide Number 6
Code 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 |
|
Slide Number 8
Steps for Fitting Data |
|
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.
|
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. | 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
|
Slide Number 10
Assignment |
For the assignment activity, please do the following.
|
Slide Number 11
Assignment |
|
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. |