Assuming that this is the data for a linear experiment with ideally, zero y-intercept:

### Data

Click here to download the data or copy the following data into a notepad and save it as a text file. I normally prefer to change the filetype from “.txt” to “.dat”, simply because, it contains data.

# m (g) | Data 1 | Data 2 | Data 3 | average | std.dev |

200 | 5.683631 | 6.29861 | 8.381023 | 6.787755 | 1.413658 |

400 | 10.23901 | 13.5709 | 15.18523 | 12.99838 | 2.522326 |

600 | 11.84209 | 11.36025 | 9.422947 | 10.8751 | 1.280467 |

800 | 16.33589 | 16.92676 | 19.82742 | 17.69669 | 1.868766 |

1000 | 22.32341 | 23.72259 | 20.2721 | 22.10603 | 1.735483 |

1200 | 24.86626 | 27.70103 | 28.07837 | 26.88189 | 1.755747 |

1400 | 28.19161 | 29.78272 | 31.26129 | 29.74521 | 1.535185 |

1600 | 34.77228 | 34.02847 | 30.23366 | 33.01147 | 2.434233 |

1800 | 37.84083 | 38.05711 | 36.07914 | 37.32569 | 1.084949 |

2000 | 37.64023 | 38.79702 | 42.7417 | 39.72632 | 2.674686 |

In this data, the first column is the mass (in grams), hung under a spring.

The spring extends and the elongation is recorded.

The experiment is repeated three times to produce three sets of data.

The average and standard deviation was calculated for these data.

### Tasks:

For this data, we would use the linear equation y = mx + c.

You would need to produce 5 fits and plots to compare the results.

These are the tasks:

- Fit and plot for Data #1 (not the average), where the parameters m and c are fitted (adjusted) to the graph.
- Fit and plot for Data #1 (not the average), where only parameter m is fitted and parameter c is fixed to zero.
- Fit and plot for Average Data, where the parameters m and c are fitted (adjusted) to the graph, without standard deviation data.
- Fit and plot for Average Data, where the parameters m and c are fitted (adjusted) to the graph, with standard deviation data.
- Fit and plot for Average Data, where only parameter m is fitted and parameter c is fixed to zero with standard deviation data.

### Required Knowledge

To perform the tasks about, one would require the basic knowledge of importing data into gnuplot.

### Code – Task 1

y1(x) = m1*x + c1

m1 = 2

c1 = 0.1

fit y1(x) ‘data.dat’ using 2:5 via m1,c1

plot ‘data.dat’ using 2:5 with points

replot y1(x) with line t “y1(x) : Single Data with y-intercept”

**Explanation**

y1(x) = m1*x + c1

First, we would need to define the fitting equation. In this case, the fitting equation is a simple linear equation with two variables, m1 and c1.

m1 = 2

c1 = 0.1

Then we assign a starting value for m1 and c1. Do not write zero. Try to write something within the same order of the actual value. The only way to know the actual value to to try to plot the graph **without fitting.**

fit y1(x) ‘data.dat’ using 2:5 via m1,c1

Next, this command fits the y1(x) equation with the data ‘data.dat‘. The command “using 2:5” selects only columns 2 and 5 for data-fitting. The values which are adjusted are written using “via m1,c1” where m1 and c1 will be changed to get the best fit.

plot ‘data.dat’ using 2:5 with points

This command plots the original data with data points

replot y1(x) with line title “y1(x) : Single Data with y-intercept”

This command plots the y1(x) equation that has been fitted with a title.