Fitting.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. %% Author: Aleks Prša
  2. % Date: July, 2022
  3. % alex.prsa@gmail.com
  4. % =========================================================================
  5. %{
  6. %
  7. % DESCRIPTION:
  8. %
  9. % Program to obtain search parameters from projection images using
  10. % optimisation function and least-square method.
  11. %
  12. % Faculty of Mathematic and Physics
  13. % University in Ljubljana
  14. % Ljubljana, Slovenia
  15. %
  16. %}
  17. % =========================================================================
  18. %% Optimisation function
  19. It = [5.1; 5.5]; % Anode current of each projection images
  20. Sb = [440.8, 479.2]; % Signal of dark side of detector
  21. Sigmab = [12.95, 18.31]; % Standard deviation od a signal of dark side of detector
  22. Sw = [27918, 30200]; % Signal of bright side of detector
  23. Sigmaw = [335.18, 350.5]; % Standard deviation od a signal of bright side of detector
  24. % Optimisation function - chi-square method
  25. R = @(x)( ...
  26. (Sb(1)-x(1)*x(2)*x(5)*It(1)-x(3))^2/1.692^2 + (Sb(2)-x(1)*x(2)*x(5)*It(2)-x(3))^2/3.741^2 + ...
  27. (Sw(1)-x(1)*x(2)*It(1)-x(3))^2/25^2 + (Sw(2)-x(1)*x(2)*It(2)-x(3))^2/25.823^2 + ...
  28. (Sigmab(1)^2-x(1)^2*x(2)*x(5)*It(1)-x(4)^2)^2/0.247^2 + (Sigmab(2)^2-x(1)^2*x(2)*x(5)*It(2)-x(4)^2)^2/0.614^2 + ...
  29. (Sigmaw(1)^2-x(1)^2*x(2)*It(1)-x(4)^2)^2/8.527^2 + (Sigmaw(2)^2-x(1)^2*x(2)*It(2)-x(4)^2)^2/3.1^2 ...
  30. );
  31. x0 = [4, 1300, 400, 10, 0.0003]; % Initial parameters
  32. [x, r] = fminsearch(R, x0);
  33. Sb1 = x(1)*x(2)*x(5)*It(1) + x(3)
  34. Sb2 = x(1)*x(2)*x(5)*It(2) + x(3)
  35. Sw1 = x(1)*x(2)*It(1) + x(3)
  36. Sw2 = x(1)*x(2)*It(2) + x(3)
  37. Sigmab1 = sqrt(x(1)^2*x(2)*x(5)*It(1) + x(4)^2)
  38. Sigmab2 = sqrt(x(1)^2*x(2)*x(5)*It(2) + x(4)^2)
  39. Sigmaw1 = sqrt(x(1)^2*x(2)*It(1) + x(4)^2)
  40. Sigmaw2 = sqrt(x(1)^2*x(2)*It(2) + x(4)^2)
  41. fprintf('Optimal parameters:\n')
  42. fprintf('\ne0:')
  43. disp(x(1))
  44. fprintf('\nalpha:')
  45. disp(x(2))
  46. fprintf('\np:')
  47. disp(x(3))
  48. fprintf('\nsigmap:')
  49. disp(x(4))
  50. fprintf('\nepsilon:')
  51. disp(x(5))
  52. fprintf('\nOstanek:')
  53. disp(r)