Contents

% *** for Lecture 5, F 2014 ***

* load previously-made fakedata (using 2nd order poly) *

load /Users/dlivelyb/matlab/phys390/fakedata
who
errorbar(x,fd,fderr,'r*','MarkerSize',12)
legend(' original data with errors','Location','SouthEast')
grid on
hold on
Your variables are:

ans          fderr        pcoeffs      pcoeffsw     ynew         
fd           p_coeffs     pcoeffs_wtg  x            yneww        

call unweighted, 1st order poly fit routine

[p_coeffs, ynew] = polyo1(x,fd);
plot(x,ynew,'r:','LineWidth',3)
legend(' original data with errors','1st order fit',...
    'Location','SouthEast')
M =

   1.0e+03 *

    0.0390    0.4095
    0.4095    5.5347


K =

   1.0e+04 *

    0.5828
    8.7099


ynew =

  Columns 1 through 7

  -49.8126  -39.3256  -28.8385  -18.3515   -7.8645    2.6225   13.1096

  Columns 8 through 14

   23.5966   34.0836   44.5706   55.0577   65.5447   76.0317   86.5188

  Columns 15 through 21

   97.0058  107.4928  117.9798  128.4669  138.9539  149.4409  159.9279

  Columns 22 through 28

  170.4150  180.9020  191.3890  201.8761  212.3631  222.8501  233.3371

  Columns 29 through 35

  243.8242  254.3112  264.7982  275.2852  285.7723  296.2593  306.7463

  Columns 36 through 39

  317.2334  327.7204  338.2074  348.6944

call weighted, 1st order poly fit routine

[pcoeffs_wtg,ynew] = polyo1_wgt(x,fd,fderr)
M =

   1.0e+04 *

    0.2738    0.5726
    0.5726    1.2934


K =

   1.0e+04 *

    3.6037
    8.6814


ynew =

  Columns 1 through 7

    0.1581    6.1167   12.0754   18.0341   23.9927   29.9514   35.9100

  Columns 8 through 14

   41.8687   47.8274   53.7860   59.7447   65.7033   71.6620   77.6207

  Columns 15 through 21

   83.5793   89.5380   95.4966  101.4553  107.4140  113.3726  119.3313

  Columns 22 through 28

  125.2900  131.2486  137.2073  143.1659  149.1246  155.0833  161.0419

  Columns 29 through 35

  167.0006  172.9592  178.9179  184.8766  190.8352  196.7939  202.7526

  Columns 36 through 39

  208.7112  214.6699  220.6285  226.5872


pcoeffs_wtg =

  -11.7593   11.9173


ynew =

  Columns 1 through 7

    0.1581    6.1167   12.0754   18.0341   23.9927   29.9514   35.9100

  Columns 8 through 14

   41.8687   47.8274   53.7860   59.7447   65.7033   71.6620   77.6207

  Columns 15 through 21

   83.5793   89.5380   95.4966  101.4553  107.4140  113.3726  119.3313

  Columns 22 through 28

  125.2900  131.2486  137.2073  143.1659  149.1246  155.0833  161.0419

  Columns 29 through 35

  167.0006  172.9592  178.9179  184.8766  190.8352  196.7939  202.7526

  Columns 36 through 39

  208.7112  214.6699  220.6285  226.5872

* plot points and fit for comparison *

plot(x,ynew,'b:','LineWidth',3)
legend(' fake data','1st order fit','1st order weighted fit',...
    'Location','SouthEast')

* now fit with weighted 2nd order poly and plot that *

[pcoeffsw,ynew] = polyo2_wgt(x,fd,fderr)
plot(x,ynew,'g-.','LineWidth',3)
legend(' fake data','1st order fit','1st order weighted fit',...
    '2nd order weighted fit','Location','SouthEast')
M =

   1.0e+05 *

    0.0274    0.0573    0.1293
    0.0573    0.1293    0.3859
    0.1293    0.3859    2.3373


K =

   1.0e+05 *

    0.3604
    0.8681
    3.4117


pcoeffsw =

    8.2060    0.1567    0.9797


ynew =

  Columns 1 through 7

    9.3424   10.6454   12.4382   14.7209   17.4935   20.7559   24.5082

  Columns 8 through 14

   28.7504   33.4824   38.7043   44.4160   50.6176   57.3091   64.4904

  Columns 15 through 21

   72.1616   80.3226   88.9735   98.1143  107.7449  117.8654  128.4757

  Columns 22 through 28

  139.5759  151.1660  163.2459  175.8157  188.8754  202.4249  216.4643

  Columns 29 through 35

  230.9935  246.0126  261.5215  277.5204  294.0090  310.9876  328.4560

  Columns 36 through 39

  346.4142  364.8624  383.8004  403.2282

* step on a point (make it an outlier), refit both non- and

    weighted, plot both, see what happens ***
figure
fd(36) = 250
[pcoeffs,ynew] = polyo2(x,fd)
errorbar(x,fd,fderr,'*b','MarkerSize',12)
grid on
hold on
plot(x,ynew,'r:','LineWidth',3)
[pcoeffsw,yneww] = polyo2_wgt(x,fd,fderr)
plot(x,yneww,'g-.','LineWidth',3)
legend(' fake data','2nd order fit','weighted 2nd order fit',...
    'Location','SouthEast')
fd =

    9.3022
    9.6312
   12.4303
   15.4115
   17.4156
   21.2976
   24.8723
   27.8214
   33.4849
   36.7443
   45.9545
   47.3680
   53.9537
   61.6495
   61.4006
   86.0215
   90.4471
   94.5414
  115.3996
  108.1307
  128.3405
  138.5569
  154.4260
  166.8194
  169.3458
  189.9641
  202.3182
  225.0999
  245.7365
  262.0189
  252.5998
  281.3340
  278.9704
  296.7541
  331.8863
  250.0000
  354.7997
  395.4594
  403.3981


M =

   1.0e+06 *

    0.0000    0.0004    0.0055
    0.0004    0.0055    0.0840
    0.0055    0.0840    1.3613


K =

   1.0e+06 *

    0.0057
    0.0847
    1.3590


pcoeffs =

    3.3891    1.7678    0.8754


ynew =

  Columns 1 through 7

    6.0323    8.0105   10.4263   13.2798   16.5710   20.2999   24.4665

  Columns 8 through 14

   29.0707   34.1127   39.5923   45.5097   51.8647   58.6574   65.8878

  Columns 15 through 21

   73.5559   81.6617   90.2052   99.1864  108.6053  118.4618  128.7561

  Columns 22 through 28

  139.4880  150.6576  162.2649  174.3099  186.7926  199.7130  213.0711

  Columns 29 through 35

  226.8669  241.1003  255.7715  270.8803  286.4268  302.4110  318.8330

  Columns 36 through 39

  335.6926  352.9898  370.7248  388.8975


M =

   1.0e+05 *

    0.0274    0.0573    0.1293
    0.0573    0.1293    0.3859
    0.1293    0.3859    2.3373


K =

   1.0e+05 *

    0.3604
    0.8680
    3.4085


pcoeffsw =

    8.1607    0.1868    0.9759


yneww =

  Columns 1 through 7

    9.3234   10.6367   12.4379   14.7271   17.5042   20.7692   24.5222

  Columns 8 through 14

   28.7631   33.4920   38.7088   44.4136   50.6062   57.2869   64.4555

  Columns 15 through 21

   72.1120   80.2564   88.8888   98.0092  107.6174  117.7137  128.2978

  Columns 22 through 28

  139.3699  150.9300  162.9780  175.5139  188.5378  202.0496  216.0494

  Columns 29 through 35

  230.5371  245.5127  260.9763  276.9278  293.3673  310.2947  327.7101

  Columns 36 through 39

  345.6133  364.0046  382.8838  402.2509