How do I get error on my experimental data (for EGR 1010)



Ok, let us say we have some measured data y at x. We have an error which for computer purposes I will represent as sy.

%
% The data is x,y, and sy ("error" -- that is the standard deviation)
%
x = [1,2,3,4,5,6];
y = [2,4,6,8,9,12];
sy =[0.6,0.2,0.4,0.3,0.5,0.4];
%
% Now to plot this data I would use the errorbar function (note this function is slightly different
% in MATLAB, but it should work similarly).
%
h1 = errorbar(x,y,sy)
%
% The above statement is good for most older Octaves, but the recent version
% of Octaves have the annoying "feature" of connected the lines of the
% error bars (something that no researcher would ever want -- after all,
% then why have error bars?). The FMT should handle this, but errobar()
% doesn't use the FMT correctly, so the following two lines will fix this.
%
set(h1,"marker","+")
set(h1,"linestyle","none")

%
% Of course this doesn't work unless you returned handle h1
%



%
% wpolyfit will be used which is a special optional package for Octave (go to packages and pick Optim --
% note that the Windows binary (from sourceforge) normally comes with this package -- though you have to
% select octave forge when you install it)
% wpolyfit allows for the error to be used as a weight. There are better ways to do this, but for this
% course, this is sufficient. The function wpolyfit is similar to polyfit where a vector is returned
% with the coefficients of the polynomial and a structure is returned that includes the Cholesky
% factors of the Vandermonde matrix plus other information that is used to create the errorbar on the fit
% (as opposed to the error on the data itself).
%
[p,s] = wpolyfit(x,y,sy,1)
%
% polyconf is used to get the values of y and sy for the MODEL (not the data).
% ci is confidence interval (remember we discussed that?) method which is
% appropriate for error bars in the physical sciences.
%
[yn,syn] = polyconf(p,x,s,'ci')
%
% Now I continue the graphing. Plotting the model over the data. And making the graph pretty. % You can do different things here depending on YOUR data.
%
hold on
plot(x,y,'b+;The data;')
plot(x,yn,'gd-;Linear model;')
xlabel('X-data (Size of the {\alpha} tiger)')
ylabel('Experiment data with error {\sigma}')
title('x versus y showing that y is linearly dependent on x')
%
% Return handle h2 so you can change the color of the model errorbars, to be different then from
% the data errorbars
%
h2=errorbar(x,yn,syn)
set(h2,"color","green")
set(h2,"marker","+")
%
% Let's neaten up a bit
%
axis([0,7,0,14])



Finally we have a graph with the data, the error on the data, the model of the data (linear fit in this case), and the error on the model data.





Note that these instructions only work for Octave. MATLAB does not have the ability to do this without special packages. Octave will not be able to do this without octave-forge. For Windows the binary comes with octave-forge, however for Macs, you need to install octave-forge.

NOTE: MATLAB should have something equivalent, but I haven't been able to find it yet; so Octave will be required in this class.

Where to get Octave:

http://www.octave.org and just follow the links.

For octave-forge go to:

http://octave.sourceforge.net/packages.html