# damped_osc_fit.dem # v 1.0 4/9/2010 L Ackermann # v 2.0 6/17/2010 R Forrest # Use this script in gnuplot or wgnuplot # ********************************** # Please insert your filename here filename = 'cavendish2a.txt' # ********************************** # This is the formula for a damped, undriven oscillator # Theta(x) = (a * exp(- d * x) * cos(om * x + phi)) + A # # a amplitude # d damping constant, equal to D/2I # om omega in rad/sec # phi phase angle # A offset of equilibrium, = 2rF/k # initial guesses a = -1 d = 0.0011 om = 0.01 phi = 0.2 A = 100 Theta(x) = (a * exp(- d * x) * cos(om * x + phi)) + A set xlabel "Time t [sec]" set ylabel "position [m]" set key below pause -1 "Data and First guess fit: (-> return)" plot filename using 1:2:3 with errorbars, Theta(x) print "Now fitting an oscillating, damped function =)" pause -1 "Now start fitting ... (-> return)" FIT_LIMIT = 1e-10 fit Theta(x) filename using 1:2:3 via a, d, om, phi, A pause -1 "Now look at the result (-> return)" set title 'Final fit' plot filename using 1:2:3 with errorbars, Theta(x)