May 21, 2024, Tuesday, 141

KADD 2022 Laboratorium 11 EN

From Łukasz Graczykowski

Jump to: navigation, search

Zadanie

Least-squares method (5 pkt.)

Using the least-squares method, fit to the data polynomials of varying degrees n=0..5.

  • Please read data from the following file. They come from the experiment of elastic collisions of negatively charged K mesons (kaons) with protons, at constant K meson energy. In the first column there are values of the cosine of the scattering angle in the rest mass reference frame, in the second column is the corresponding number of collisions. As errors please assume the square root of the number of observations. The degree of fitted polynomial allows to calculate the spin quantum numbers of intermediate stages ("Analiza danych", S.Brandt, Przykład 9.2.).
  • Please implement the function realizing the least-squares method. Use formulas from the lecture (ich wyprowadzenie znajduje się w Lecture 12 and from the unstruction instrukcji) - please carefully read the instruction - all the steps should follow the instruction:

Wzor1 new asd.png

Wzor2.png

Wzor3.png

Wzor4.png

Wzor567.png

Wzor89.png

Comment: we search from a minimum of M function (equivalent of chi-squared statistics), values t_{j} are the cosine scattering functions (first column from the file), values y_{j} are the observations numbers (second column). Estimators x are the searched parameters (coefficients) of the polynomial.

Example function definition:

// Function returns M
// parameters:
//  st - degree of the polynomial
//  n - number of measurements
//  tj - array of cosine of scattering angles
//  yj - measurement results
//  sigmaj - measurement errors
//  wsp - array in which we need to save estimated coefficients (Wzor10.png)
//  bswp - array in which we need to save estimated coefficient errors (square roots of the diagonal elements of the matrix  Wzor11.png)
double fit (int st, int n, double *tj, double *yj, double *sigmaj, double *wsp, double *bwsp);

To implement the formulas please use the class TMatrixD. Examples:

// utworzenie macierzy o wymiarach n x m
TMatrixD *macierzA = new TMatrixD(n,m);
// dostep do elementu o indeksach i,j macierzy macierzA, np.:
(*macierzA)(i,j) = 1;
// mnozenie macierzy: macierzA = macierzB macierzC
TMatrixD *macierzA = new TMatrixD(*macierzB, TMatrix::kMult, *macierzC);
// transponowanie macierzy
TMatrixD *macierzAt = new TMatrixD(TMatrix::kTransposed,*macierzA);
// odwracanie macierzy
macierz->Invert();
  • Please interpret the resulting fitting by performing a chi-squared test (using the M functions). Please state which degree of the polynomial fits data best (what is the lowest degree of the polynomial, for which we do not reject the null hypothesis)

Result

Mnk 2.png

Output:
 Dopasowanie wielomianem stopnia 0
 M = 833.548
 x0 = 57.8452 +- 2.4051
 Liczba stopni swobody=9
 Kwantyl=21.666
 Poziom istotnosci=0.01
 Stopien 0: odrzucamy
 Dopasowanie wielomianem stopnia 1
 M = 585.449
 x0 = 82.6551 +- 2.87498
 x1 = 99.0998 +- 6.29159
 Liczba stopni swobody=8
 Kwantyl=20.0902
 Poziom istotnosci=0.01
 Stopien 1: odrzucamy
 Dopasowanie wielomianem stopnia 2
 M = 36.4096
 x0 = 47.267 +- 3.24753
 x1 = 185.955 +- 7.30235
 x2 = 273.612 +- 11.6771
 Liczba stopni swobody=7
 Kwantyl=18.4753
 Poziom istotnosci=0.01
 Stopien 2: odrzucamy
 Dopasowanie wielomianem stopnia 3
 M = 2.84989
 x0 = 37.949 +- 3.62403
 x1 = 126.546 +- 12.5894
 x2 = 312.018 +- 13.4278
 x3 = 137.585 +- 23.7499
 Liczba stopni swobody=6
 Kwantyl=16.8119
 Poziom istotnosci=0.01
 Stopien 3: akceptujemy
 Dopasowanie wielomianem stopnia 4
 M = 1.68602
 x0 = 39.6179 +- 3.94036
 x1 = 119.102 +- 14.3563
 x2 = 276.49 +- 35.5643
 x3 = 151.91 +- 27.2096
 x4 = 52.5999 +- 48.7566
 Liczba stopni swobody=5
 Kwantyl=15.0863
 Poziom istotnosci=0.01
 Stopien 4: akceptujemy
 Dopasowanie wielomianem stopnia 5
 M = 1.66265
 x0 = 39.8786 +- 4.29351
 x1 = 121.384 +- 20.7054
 x2 = 273.188 +- 41.6103
 x3 = 136.571 +- 103.954
 x4 = 56.8995 +- 56.2858
 x5 = 16.7294 +- 109.424
 Liczba stopni swobody=4
 Kwantyl=13.2767
 Poziom istotnosci=0.01
 Stopien 5: akceptujemy