More Gnuplot

Fitting functions to data

Part 1: Fitting

Fitting Functions to Data

gnuplot> fit m*x + b 'data.txt' via m,b

Demo : Simple fits

./demos/01-linear_fit.sh

Part 2: Fitting with uncertainty

Recall

gnuplot> plot 'data.txt' u 1:2:4 with yerrorbars
gnuplot> plot 'data.txt' u 1:2:3 with xerrorbars
gnuplot> plot 'data.txt' u 1:2:3:4 with xyerrorbars

We can also tell Gnuplot to consider error bars when fitting

Fitting Functions to Data with Errors

gnuplot> fit m*x + b 'data.txt' using 1:2:4 yerrors via m,b
gnuplot> fit m*x + b 'data.txt' using 1:2:3:4 xyerrors via m,b

Demo : Error bars

./demos/02-dataerror_fit.sh

Practice

Gaussian Fit

\[N(x,\mu,\sigma) = A e^{-\frac{1}{2} \frac{(x-\mu)^2}{\sigma^2}}\]

ERROR: could not create image

Example

./demos/03-gaussian_fit.sh

Fitting with column transformations

We can use column transformations to transform the data before we fit a function

gnuplot> fit m*x + b 'data.txt' u 2:($1*$1) via m,b

./demos/04-fitting_with_column_transformation.sh

Fitting difficult functions

Harmonic Oscillator

Recall that, for a mass osccilating on a spring, we have

\[y(t) = A\sin(\omega t)\] \[v(t) = \frac{dy}{dt} = A\omega\cos(\omega t)\] \[a(t) = \frac{dy}{dt} = -A\omega^2\sin(\omega t)\] \[T = \frac{1}{f} = \frac{2\pi}{\omega}\] \[\omega = \sqrt{\frac{k}{m}} \rightarrow k = (m\omega)^2\]

./demos/05-fitting_difficult_functions.sh

2D plots

Gnuplot can plot functions of two variables as well.

ERROR: could not create image

Last Slide

Last Slide

Last Slide

Last Slide

Last Slide

Last Slide

Last Slide

Last Slide

Last Slide

Last Slide

Last Slide

Example 2: Kinematics

Say we have collected data for an experiment in Physics I, we recorded the position of a cart under constant acceleration.

Example 2: Kinematics

Example 2: Kinematics

What is the initial velocity of the cart?

. . .

Example 2: Kinematics

What is the acceleration of the cart?

. . .

Example 2: Kinematics

At what time does the cart turn around?

. . .

Example 2: Kinematics

How far does the cart travel before it turns around?

. . .

Example 2: Kinematics

Is the cart moving faster at the beginning or the end of the data collection period?

Example 3: Harmonic Oscillator Measurement

Say we have collected data for an experiment in Physics I, we recorded the position of a mass on a spring while it oscillates and eventually comes to rest.

Example 3: Harmonic Oscillator Measurement

Example 3: Harmonic Oscillator Measurement

Example 3: Harmonic Oscillator Measurement

Example 3: Harmonic Oscillator Measurement

What is the maximum displacement of the mass?

. . .

Example 3: Harmonic Oscillator Measurement

What is the maximum speed of the mass?

. . .

Example 3: Harmonic Oscillator Measurement

If the mass is 1 kg, what is the spring constant of the spring?

. . .

Example 3: Harmonic Oscillator Measurement

What is the period of oscillation?

. . .