I would like to know how to perform a nonlinear regression on a table with measurement errors. The table consists of two columns, and both have errors. I've been watching some tutorial and it is very well explained how to make a nonlinear regression if only one of the columns have errors.
This is the complete data I import, which is acquired from an oscilloscope (first column is time and second is voltage):
data1={{0,2.8},{0.01,4},{0.02,7.2},{0.03,9.6},{0.04,12},{0.05,14.4},{0.06,16.4},{0.07,18.4},{0.08,20},{0.09,21.2},{0.1,22.4},{0.11,23.2},{0.12,24},{0.13,24.4},{0.14,24.4},{0.15,24.4},{0.16,24},{0.17,23.6},{0.18,22.4},{0.19,21.6},{0.2,20.4},{0.21,19.2},{0.22,17.6},{0.23,16},{0.24,14.4},{0.25,12.4},{0.26,10.4},{0.27,8.4},{0.28,6.4},{0.29,4.4},{0.3,2.4},{0.31,0.4},{0.32,-1.2},{0.33,-3.2},{0.34,-5.2},{0.35,-6.8},{0.36,-8.4},{0.37,-9.6},{0.38,-10.8},{0.39,-12},{0.4,-13.2},{0.41,-14},{0.42,-14.4},{0.43,-15.2},{0.44,-15.6},{0.45,-15.6},{0.46,-15.6},{0.47,-15.6},{0.48,-15.2},{0.49,-14.8},{0.5,-14.4},{0.51,-13.6},{0.52,-12.8},{0.53,-12},{0.54,-11.2},{0.55,-10},{0.56,-8.8},{0.57,-7.6},{0.58,-6.4},{0.59,-5.2},{0.6,-4},{0.61,-2.8},{0.62,-1.2},{0.63,0},{0.64,1.2},{0.65,2},{0.66,3.2},{0.67,4.4},{0.68,5.2},{0.69,6},{0.7,6.8},{0.71,7.6},{0.72,8.4},{0.73,8.8},{0.74,9.2},{0.75,9.6},{0.76,9.6},{0.77,10},{0.78,10},{0.79,9.6},{0.8,9.6},{0.81,9.2},{0.82,8.8},{0.83,8.4},{0.84,8},{0.85,7.2},{0.86,6.8},{0.87,6},{0.88,5.2},{0.89,4.8},{0.9,4},{0.91,3.2},{0.92,2.4},{0.93,1.6},{0.94,0.8},{0.95,-0.4},{0.96,-0.8},{0.97,-1.6},{0.98,-2.4},{0.99,-3.2},{1,-3.6},{1.01,-4.4},{1.02,-4.8},{1.03,-5.2},{1.04,-5.6},{1.05,-6},{1.06,-6},{1.07,-6.4},{1.08,-6.4},{1.09,-6.4},{1.1,-6.4},{1.11,-6.4},{1.12,-6.4},{1.13,-6},{1.14,-6},{1.15,-5.6},{1.16,-5.2},{1.17,-4.8},{1.18,-4.4},{1.19,-4},{1.2,-3.6},{1.21,-3.2},{1.22,-2.4},{1.23,-2},{1.24,-1.2},{1.25,-0.8},{1.26,-0.4},{1.27,0},{1.28,0.8},{1.29,1.2},{1.3,1.6},{1.31,2},{1.32,2.4},{1.33,2.8},{1.34,2.8},{1.35,3.2},{1.36,3.6},{1.37,3.6},{1.38,4},{1.39,4},{1.4,4},{1.41,4},{1.42,4},{1.43,4},{1.44,4},{1.45,3.6},{1.46,3.6},{1.47,3.2},{1.48,3.2},{1.49,2.8},{1.5,2.4},{1.51,2.4},{1.52,2},{1.53,1.6},{1.54,1.2},{1.55,1.2},{1.56,0.8},{1.57,0.4},{1.58,0},{1.59,-0.4},{1.6,-0.4},{1.61,-0.8},{1.62,-1.2},{1.63,-1.6},{1.64,-1.6},{1.65,-1.6},{1.66,-2},{1.67,-2},{1.68,-2.4},{1.69,-2.4},{1.7,-2.8},{1.71,-2.8},{1.72,-2.8},{1.73,-2.8},{1.74,-2.8},{1.75,-2.8},{1.76,-2.4},{1.77,-2.4},{1.78,-2.4},{1.79,-2},{1.8,-2},{1.81,-2},{1.82,-1.6},{1.83,-1.6},{1.84,-1.2},{1.85,-1.2},{1.86,-0.8},{1.87,-0.8},{1.88,-0.4},{1.89,-0.4},{1.9,0},{1.91,0},{1.92,0.4},{1.93,0.4},{1.94,0.8},{1.95,0.8},{1.96,1.2},{1.97,1.2},{1.98,1.2},{1.99,1.2},{2,1.6},{2.01,1.6},{2.02,1.6},{2.03,1.6},{2.04,1.6},{2.05,1.6},{2.06,1.6},{2.07,1.6},{2.08,1.6},{2.09,1.6},{2.1,1.2},{2.11,1.2},{2.12,1.2},{2.13,1.2},{2.14,1.2},{2.15,0.8},{2.16,0.8},{2.17,0.8},{2.18,0.4},{2.19,0.4},{2.2,0.4},{2.21,0},{2.22,0},{2.23,-0.4},{2.24,-0.4},{2.25,-0.4},{2.26,-0.4},{2.27,-0.8},{2.28,-0.8},{2.29,-0.8},{2.3,-0.8},{2.31,-0.8},{2.32,-0.8},{2.33,-1.2},{2.34,-1.2},{2.35,-1.2},{2.36,-1.2},{2.37,-1.2},{2.38,-1.2},{2.39,-1.2},{2.4,-1.2},{2.41,-0.8},{2.42,-0.8},{2.43,-0.8},{2.44,-0.8},{2.45,-0.8},{2.46,-0.8},{2.47,-0.4},{2.48,-0.4},{2.49,-0.4},{2.5,-0.4},{2.51,-0.4},{2.52,-0.4},{2.53,0},{2.54,0},{2.55,0},{2.56,0},{2.57,0.4},{2.58,0.4},{2.59,0.4},{2.6,0.4},{2.61,0.4},{2.62,0.4},{2.63,0.4},{2.64,0.4},{2.65,0.8},{2.66,0.8},{2.67,0.8},{2.68,0.8},{2.69,0.8},{2.7,0.8},{2.71,0.8},{2.72,0.4},{2.73,0.4},{2.74,0.4},{2.75,0.4},{2.76,0.4},{2.77,0.4},{2.78,0.4},{2.79,0.4},{2.8,0.4},{2.81,0},{2.82,0},{2.83,0},{2.84,0},{2.85,0},{2.86,0},{2.87,0},{2.88,0},{2.89,-0.4},{2.9,-0.4},{2.91,-0.4},{2.92,-0.4},{2.93,-0.4},{2.94,-0.4},{2.95,-0.4},{2.96,-0.4},{2.97,-0.4},{2.98,-0.4},{2.99,-0.4},{3,-0.4},{3.01,-0.4},{3.02,-0.4},{3.03,-0.4},{3.04,-0.4},{3.05,-0.4},{3.06,-0.4},{3.07,-0.4},{3.08,-0.4},{3.09,-0.4},{3.1,-0.4},{3.11,-0.4},{3.12,-0.4},{3.13,-0.4},{3.14,0},{3.15,0},{3.16,0},{3.17,0},{3.18,0},{3.19,0},{3.2,0},{3.21,0},{3.22,0},{3.23,0},{3.24,0},{3.25,0},{3.26,0},{3.27,0},{3.28,0.4},{3.29,0.4},{3.3,0.4},{3.31,0.4},{3.32,0.4},{3.33,0.4},{3.34,0.4},{3.35,0.4},{3.36,0},{3.37,0},{3.38,0},{3.39,0},{3.4,0},{3.41,0},{3.42,0},{3.43,0},{3.44,0},{3.45,0},{3.46,0},{3.47,0},{3.48,0},{3.49,0},{3.5,0},{3.51,0},{3.52,0},{3.53,0},{3.54,0},{3.55,0},{3.56,-0.4},{3.57,-0.4},{3.58,-0.4},{3.59,-0.4},{3.6,-0.4},{3.61,-0.4},{3.62,-0.4},{3.63,-0.4},{3.64,-0.4},{3.65,-0.4},{3.66,-0.4},{3.67,-0.4},{3.68,-0.4},{3.69,-0.4},{3.7,-0.4},{3.71,-0.4},{3.72,-0.4},{3.73,0},{3.74,0},{3.75,0},{3.76,0},{3.77,0},{3.78,0},{3.79,0},{3.8,0},{3.81,0},{3.82,0},{3.83,0},{3.84,0},{3.85,0},{3.86,0},{3.87,0},{3.88,0},{3.89,0},{3.9,0},{3.91,0},{3.92,0},{3.93,0},{3.94,0},{3.95,0},{3.96,0},{3.97,0},{3.98,0},{3.99,0},{4,0},{4.01,0},{4.02,0},{4.03,0},{4.04,0},{4.05,0},{4.06,0}}
This is the code I used to fit with errors on the voltage (second) column.
y = b Exp[-a x] Sin[ω x + φ];
yerror = ConstantArray[0.001, Length[data1]];
nlm = NonlinearModelFit[
data1,
y, {a, b, ω, φ}, x,
Weights -> yerror^(-2), VarianceEstimatorFunction -> (1 &)
]
Now, this gives a nice fit but my table consists of two columns, with different measurement errors. Is there any way to make a fit that considers both errors?
Thanks in advance.
Sqrt[xError^2+yError^2], or, since you have a model function, propagating that error through and finding ayErrorFromXand then using the overall error asSqrt[yErrorFromX^2+yError^2]. Then you can just use the single weight function. – tkott Sep 20 '12 at 17:54NonlinearModelFitet al.), although the documentation may still be of some interest. – Oleksandr R. Sep 20 '12 at 19:53