In this workshop, we will use GnuPlot and a spreadsheet to do linear regression and look at some of the analysis parameters.

To run GnuPlot on the web open http://www.plotshare.com  in another browser tab or window.

Note that the plotshare requires you to prove you are human by entering the text presented in the Options box just below the main Gnuplot-Script box at the top of the page.

Copy / paste the script from Example 6.03.1 below into the Gnuplot-Script box on plotshare, then Add external data and copy / paste the data after the script into the text box ExtData1.

Click Execute to fit line and plot the end result. That’s all it takes to do regression with Gnuplot.

Replace the script and the data with the information under Example 6.03.2.

Download the spreadsheet version here and a picture explaining the steps to complete the regression in the spreadsheet here. A good description of the use of LINEST is provided here by Microsoft.

For another example, but for a more general least squares fit, look at this MAT113 workshop exercise.

Example 6.03.1

Script

# === The linear equation ===
T(x) = k1 + k2 * x
# === The regression command ===
fit T(x) 'ExtData1' via k1, k2
# === Plotting with nice formatting ===
set key inside bottom right title 'Legend' box 3
set xlabel 'Angle, radians'
set ylabel 'Torque, N-m'
set xrange [0.5:2.0]
set yrange [0.1:0.4]
set linetype 1 lw 2 lc rgb "blue" pointtype 6
set linetype 2 lw 2 lc rgb "forest-green" pointtype 8
plot T(x) title 'Torque line', 'ExtData1' title 'Torque data'
ExtData1

# Angle,  Torque
#Radians, N-m·
0.698132  0.188224
0.959931  0.209138
1.134464  0.230052
1.570796  0.250965
1.919862  0.313707

Example 6.03.2

Script

# === The linear equation ===
S(x) = E * x
# === The regression command ===
fit S(x) 'ExtData1' via E
# === Plotting with nice formatting ===
set key inside bottom right title 'Legend' box 3
set xlabel 'Strain (%)'
set ylabel 'Stess (MPa)'
set xrange [0:1.6]
set yrange [0:3000]
plot S(x) title 'Modulus line', 'ExtData1' title 'Strain data'
ExtData1

# epsilon sigma
0  0
0.183  306
0.36  612
0.5324 917
0.702  1223
0.867  1529
1.0244 1835
1.1774 2140
1.329  2446
1.479  2752
1.5  2767
1.56  2896