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:'''...")
 
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
  
'''Keywords:''' gnuplot, video tutorial, spoken tutorial, data fitting, regression, error bars
+
|-
 +
|| Visual Cue
 +
|| Narration
  
 +
|-
 +
||'''Slide Number 1'''
 +
'''Title Slide '''
 +
'''Data fitting and error bars'''
 +
||Welcome to the tutorial on '''Data fitting and error bars'''
  
{| 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 2'''
! align=center style="background-color:#993366;border:1pt solid #000000;padding:0.0382in;" | Narration
+
'''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
 +
 
 
|-
 
|-
| 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 3'''
 +
'''System and Software Requirement'''
 +
||*Debian Linux 9 .3
 +
*Gedit 3.22.0 and
 +
*gnuplot 5.2.5 installed
  
<div style="color:#000000;">'''Title Slide '''</div>
+
|-
 +
||'''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.
  
<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>
+
|| 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.
  
<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>
+
|| 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.
  
<div style="color:#000000;">'''Learning Objectives'''</div>
+
|-
 
+
|| Close '''gedit'''
 
+
|| 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:1pt solid #000000;padding:0.0382in;" | <div style="color:#000000;">In this tutorial, we will learn,</div>
+
 
+
 
+
* <div style="color:#000000;">Learn to add error bars in a graph</div>
+
* <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>
+
  
 +
|-
 +
||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.
  
 
|-
 
|-
| 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>
+
||'''gnuplot'''
 +
|| Open '''gnuplot'''.
 +
Type '''gnuplot''' and '''enter'''
  
<div style="color:#000000;">'''System and Software Requirement'''</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;">Debian Linux</div>
 
 
 
<div style="color:#000000;">Gedit 3.22.0</div>
 
 
<div style="color:#000000;">and</div>
 
 
<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>
+
|| Show qt on screen.
 +
||'''Set''' '''terminal''' as necessary.
 +
For me it is already in '''qt'''.
  
<div style="color:#000000;">'''Samson Microphone'''</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 record audio, I am using '''Samson''' '''USB''' portable microphone was used.</div>
 
 
 
<div style="color:#000000;">The model number '''SAGOMIC'''</div>
 
 
 
<div style="color:#000000;">I bought it from '''amazon''' website, for about rupees four thousand</div>
 
 
 
<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>
+
|| '''Ctrl-l'''
 
+
|| I will clear screen with command control l.
<div style="color:#000000;">'''Pre-requisites'''</div>
+
This takes terminal prompt to top of the screen for clarity in video.
 
+
 
+
<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>
+
 
+
 
+
<div style="color:#000000;">Basic computer and internet skills</div>
+
 
+
 
+
<div style="color:#000000;">Concept of graphing </div>
+
 
+
<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>
+
||  
 +
|| First, let's plot the data to see the trend and for visual inspection.
  
<div style="color:#000000;">'''Pre-requisites'''</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;" | <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>
 
 
 
<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'''.
+
|| '''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;" | <div style="color:#000000;">First, we will first learn to incorporate error bars in a graph.</div>
+
|| Enter the plot command as seen on the screen.
  
 
<div style="color:#000000;">First, Go to '''Desktop'''.</div>
 
 
 
<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>
+
|| If error limits are on the x data, we can use, x error bars term for plotting.
 +
The graphic window opens.
  
 
<div style="color:#000000;">Double click on the file icon to open it in a text editor.</div>
 
 
 
<div style="color:#000000;">The file opens in gedit for me.</div>
 
 
 
<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;" |  
+
||  
| 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.
+
|| The colon 3 with y error bars in the plot command adds the error to the plot.
  
 
Second column is '''y''' data.
 
 
 
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'''
+
|| 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;" | Close '''gedit''' by clicking on the x-sign.
+
|| 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;" | <div style="color:#000000;">Press '''ctrl alt t'''</div>
+
  
 
<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>
+
||  
 +
|| This data likely represent an exponential decay.
  
<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.
+
||  
| 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>
+
|| The points may be off the ideal curve due to measurement errors.
  
 
<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'''
+
||  
| 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.
+
|| We will fit the given data points to an exponential decay function.
  
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;" |
 
| 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.
 
|-
 
| 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 see a few steps involved in fitting data points to an equation.
  
 
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;" |  
+
||'''Slide Number 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;" | The colon 3 with y error bars in the plot command adds the error to the plot.
+
|-
+
| 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>
+
 
+
 
'''Steps in data fitting'''
 
'''Steps in data fitting'''
 
+
|| First, define a function to represent the data
 
+
Find a function to represent the data
+
 
+
Initial guess values for constants
+
 
+
 
+
A good fitting, measured by chi square
+
 
+
 
+
Find the 'optimal' value of the constants in the function
+
 
+
 
+
<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
+
 
+
 
+
 
Make initial guess values for constants
 
Make initial guess values for constants
 
 
 
A good fitting, measured by '''chi square''' value
 
A good fitting, measured by '''chi square''' value
 
 
 
Find the 'optimal' value of the constants in the function
 
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
  
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)'''
+
|| Go to graphical 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;">First, let's define the function.</div>
+
||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
  
<div style="color:#000000;">Type '''f''' of '''x''' is equal to a times '''e''' to the power minus '''k x'''</div>
+
|-
 +
||
 +
|| 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.
  
<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.
+
||'''a=150000 '''
| 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>
+
'''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
  
<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
+
|| If column 3 is not mentioned, the y axis uncertainties is not considered for data fitting.
 +
 
 
|-
 
|-
| 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
+
|| 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;" | Close the graphical window and go to gnuplot terminal prompt.
+
|| 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;" | <div style="color:#000000;">'''a=150000 '''</div>
+
||  
 +
|| I see an error , warning message on top
  
<div style="color:#000000;">'''k=0.5'''</div>
+
|-
 +
||
 +
|| 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.
  
| 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>
+
|-
 +
||
 +
||Notice, relative change in values after the last iteration.
 +
The number is very small
  
<div style="color:#000000;">Enter a equal to fifteen hundred thousand</div>
+
|-
 +
||
 +
|| Degrees of freedom is 9
  
<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'''
+
||  
| 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>
+
|| The root mean square or RMS is around 0.17
  
 +
|-
 +
||
 +
|| Updated values of a and k and their error in estimation is also shown.
  
<div style="color:#000000;">Fit space f of x space in double quotes error hyphen bar dot txt. </div>
+
|-
 +
||
 +
|| The correlation matrix of variables is at the end of the output.
  
 
<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;" |  
+
||  
| 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 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;" | 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;" |  
+
||  
| 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>
+
|| Let's plot the data points and function together.
  
 
<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;" |  
+
||  
| 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>
+
||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.
  
 
<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;" |
 
| 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
 
|-
 
| 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;" |
+
|| '''plot f(x) lw 2 title 'fitted data', "error-bar-fitting.txt" using 1:2:3 with yerrorbars pt 7 ps 1.5 notitle'''
| 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>
+
||Then, enter the plot command as seen on the screen.
  
 
<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'''
+
||  
| 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>
+
||I will modify to change legend as '''fitted data''' for f of x.
 
+
It is represented by a line with width 2.
 
+
  
 
|-
 
|-
| 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;">I will modify to change legend as '''fitted data''' for f of x.</div>
+
||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
  
 
<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;" |
+
|| '''set xrange [0.95:5.05]'''
| 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>
+
||Please pause video as necessary to practice.
 +
Let's also set x axis limits with set xrange command as seen in the video.
  
 
<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]'''
+
|| '''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;" | <div style="color:#000000;">Please pause video as necessary to practice.</div>
+
|| Replot to see the results.
  
 
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'''
+
||'''Slide Number 6'''
| 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.
+
'''Summary'''
|-
+
|| Now let’s summarize.  
| 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>
+
 
+
<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
 
In this tutorial, we learned to
 
 
 
* Display error bars in a graph
 
* Display error bars in a graph
 
* Fit a given set of data points to an equation<br/>and
 
* Fit a given set of data points to an equation<br/>and
Line 367: Line 261:
  
 
|-
 
|-
| 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 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.
  
<div style="color:#000000;">'''Assignment'''</div>
+
|-
 +
||'''Slide Number 8'''
 +
'''Spoken Tutorial Project'''
 +
||This video summarises the Spoken Tutorial Project
 +
Please download and watch it.
  
 
<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 9'''
 +
'''Spoken Tutorial workshops'''
 +
||We conduct workshops and give certificates.
 +
Please write to us.
  
<div style="color:#000000;">'''Spoken Tutorial Project'''</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;" | <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 10'''
 +
'''Forum for specific questions:'''
 +
|| Post your timed queries in the forum.
  
<div style="color:#000000;">'''Spoken Tutorial workshops'''</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;" | <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 11'''
 +
'''Acknowledgement'''
 +
||Spoken Tutorial Project is funded by NMEICT, 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>
+
||  
 +
|| 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>
 

Revision as of 16:09, 11 March 2019

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