
# 21 July 2025
# Reference output of capfit_examples.py 
#
# Python 3.13.5
# Numpy 2.3.1
# Scipy 1.16.0
# Matplotlib 3.10.3
# CapFit 2.7.0

#### Example unconstrained case ####


Start lambda: 29.19  chi2: 7492.
Start p[free]: 1.000 1.000 1.000

iter: 1  lambda: 29.19  chi2: 9153.  ratio: -0.3542
p[free]: -0.3362 0.2438 2.237
dp: -1.336 -0.7562 1.237

iter: 1  lambda: 116.7  chi2: 8242.  ratio: -0.1610
p[free]: -0.2556 0.2628 2.147
dp: -1.256 -0.7372 1.147

iter: 1  lambda: 467.0  chi2: 6177.  ratio: 0.2987
p[free]: -0.01517 0.3316 1.885
dp: -1.015 -0.6684 0.8848

iter: 2  lambda: 467.0  chi2: 4336.  ratio: 0.9157
p[free]: 0.5492 0.4629 1.867
dp: 0.5644 0.1313 -0.01763

iter: 3  lambda: 233.5  chi2: 3528.  ratio: 0.4242
p[free]: 0.5007 -1.908 2.272
dp: -0.04847 -2.371 0.4047

iter: 4  lambda: 233.5  chi2: 2269.  ratio: 1.645
p[free]: 0.7605 -0.7600 1.117
dp: 0.2598 1.148 -1.155

iter: 5  lambda: 116.7  chi2: 3839.  ratio: -1.019
p[free]: 1.435 -1.355 0.1819
dp: 0.6748 -0.5946 -0.9352

iter: 5  lambda: 467.0  chi2: 1965.  ratio: 0.2083
p[free]: 1.311 -1.299 0.3908
dp: 0.5508 -0.5386 -0.7262

iter: 6  lambda: 1868.  chi2: 378.7  ratio: 0.9513
p[free]: 1.492 -1.018 0.6198
dp: 0.1811 0.2806 0.2290

iter: 7  lambda: 933.9  chi2: 122.0  ratio: 0.9663
p[free]: 1.822 -1.004 0.5212
dp: 0.3292 0.01389 -0.09863

iter: 8  lambda: 467.0  chi2: 80.05  ratio: 0.9958
p[free]: 1.985 -1.006 0.5090
dp: 0.1634 -0.001649 -0.01224

iter: 9  lambda: 233.5  chi2: 79.14  ratio: 0.9769
p[free]: 2.013 -1.005 0.5055
dp: 0.02789 0.0003761 -0.003514

iter: 10  lambda: 116.7  chi2: 79.14  ratio: 0.7772
p[free]: 2.015 -1.005 0.5052
dp: 0.002009 4.845e-05 -0.0002190

Terminating on small function variation (ftol)
Final iter: 10  Func calls: 44  chi2: 79.14  Status: 2
Final p[free]: 2.015 -1.005 0.5052


#### Example tied parameters ####


Start lambda: 32.91  chi2: 2251.
Start p[free]: 1.000 1.000

iter: 1  lambda: 32.91  chi2: 812.1  ratio: 1.917
p[free]: 1.549 0.5325
dp: 0.5489 -0.4675

iter: 2  lambda: 16.45  chi2: 81.30  ratio: 1.084
p[free]: 2.017 0.5157
dp: 0.4680 -0.01676

iter: 3  lambda: 8.227  chi2: 79.15  ratio: 0.9607
p[free]: 2.012 0.5054
dp: -0.005077 -0.01029

iter: 4  lambda: 4.114  chi2: 79.15  ratio: 1.843
p[free]: 2.012 0.5058
dp: -0.0001930 0.0003436

Terminating on small function variation (ftol)
Final iter: 4  Func calls: 13  chi2: 79.15  Status: 2
Final p[free]: 2.012 0.5058


#### Example fixed parameters ####


Start lambda: 29.25  chi2: 7437.
Start p[free]: 1.000 1.000

iter: 1  lambda: 29.25  chi2: 6076.  ratio: 0.9960
p[free]: 0.04513 0.9550
dp: -0.9549 -0.04505

iter: 2  lambda: 14.62  chi2: 6064.  ratio: 2.506
p[free]: 0.04026 0.5827
dp: -0.004871 -0.3723

iter: 3  lambda: 7.311  chi2: 5687.  ratio: 2.892
p[free]: 0.1443 -1.849
dp: 0.1040 -2.432

iter: 4  lambda: 3.656  chi2: 6131.  ratio: -0.1423
p[free]: 0.9986 3.648
dp: 0.8543 5.497

iter: 4  lambda: 14.62  chi2: 7069.  ratio: -0.4529
p[free]: 0.9956 2.846
dp: 0.8513 4.695

iter: 4  lambda: 58.49  chi2: 7413.  ratio: -0.6553
p[free]: 0.9836 1.116
dp: 0.8393 2.965

iter: 4  lambda: 234.0  chi2: 2462.  ratio: 1.766
p[free]: 0.9374 -0.6509
dp: 0.7931 1.199

iter: 5  lambda: 117.0  chi2: 1014.  ratio: 0.6522
p[free]: 1.755 -1.295
dp: 0.8179 -0.6442

iter: 6  lambda: 117.0  chi2: 119.3  ratio: 1.053
p[free]: 1.863 -0.9950
dp: 0.1077 0.3001

iter: 7  lambda: 58.49  chi2: 79.51  ratio: 1.000
p[free]: 2.024 -1.006
dp: 0.1614 -0.01093

iter: 8  lambda: 29.25  chi2: 79.50  ratio: 1.007
p[free]: 2.026 -1.005
dp: 0.001138 0.0006958

Terminating on small function variation (ftol)
Final iter: 8  Func calls: 28  chi2: 79.50  Status: 2
Final p[free]: 2.026 -1.005


#### Example bounds on parameters ####


Start lambda: 29.19  chi2: 7492.
Start p[free]: 1.000 1.000 1.000

iter: 1  lambda: 29.19  chi2: 9106.  ratio: -0.3461
p[free]: -0.3327 0.2426 2.224
dp: -1.333 -0.7574 1.224

iter: 1  lambda: 116.7  chi2: 8202.  ratio: -0.1531
p[free]: -0.2521 0.2610 2.134
dp: -1.252 -0.7390 1.134

iter: 1  lambda: 467.0  chi2: 6155.  ratio: 0.3053
p[free]: -0.01185 0.3287 1.873
dp: -1.012 -0.6713 0.8734

iter: 2  lambda: 467.0  chi2: 4300.  ratio: 0.9332
p[free]: 0.5509 0.4316 1.859
dp: 0.5628 0.1029 -0.01409

iter: 3  lambda: 233.5  chi2: 3478.  ratio: 0.5779
p[free]: 0.5079 -0.9500 2.350
dp: -0.04301 -1.382 0.4906

iter: 4  lambda: 233.5  chi2: 2176.  ratio: 1.430
p[free]: 0.7957 -0.9500 0.5500
dp: 0.2878 0.000 -1.800

iter: 5  lambda: 116.7  chi2: 144.1  ratio: 1.000
p[free]: 1.846 -0.9500 0.5500
dp: 1.050 0.000 0.000

iter: 6  lambda: 58.37  chi2: 134.8  ratio: 1.000
p[free]: 1.921 -0.9500 0.5500
dp: 0.07501 0.000 0.000

iter: 7  lambda: 29.19  chi2: 134.8  ratio: 1.000
p[free]: 1.922 -0.9500 0.5500
dp: 0.001211 0.000 0.000

Terminating on small function variation (ftol)
Final iter: 7  Func calls: 31  chi2: 134.8  Status: 2
Final p[free]: 1.922 -0.9500 0.5500


#### Example Jacobian scaling with unscaled variables ####


Start lambda: 29.19  chi2: 7492.
Start p[free]: 1.000 1.000e+10 1.000

iter: 1  lambda: 29.19  chi2: 9106.  ratio: -0.3461
p[free]: -0.3327 2.426e+09 2.224
dp: -1.333 -7.574e+09 1.224

iter: 1  lambda: 116.7  chi2: 8202.  ratio: -0.1531
p[free]: -0.2521 2.610e+09 2.134
dp: -1.252 -7.390e+09 1.134

iter: 1  lambda: 467.0  chi2: 6155.  ratio: 0.3053
p[free]: -0.01185 3.287e+09 1.873
dp: -1.012 -6.713e+09 0.8734

iter: 2  lambda: 467.0  chi2: 4300.  ratio: 0.9332
p[free]: 0.5509 4.316e+09 1.859
dp: 0.5628 1.029e+09 -0.01409

iter: 3  lambda: 233.5  chi2: 3491.  ratio: 0.4305
p[free]: 0.5155 -1.919e+10 2.214
dp: -0.03546 -2.350e+10 0.3550

iter: 4  lambda: 233.5  chi2: 2384.  ratio: 1.383
p[free]: 0.7644 -6.361e+09 1.058
dp: 0.2490 1.283e+10 -1.157

iter: 5  lambda: 116.7  chi2: 3302.  ratio: -0.5574
p[free]: 1.387 -1.535e+10 0.3737
dp: 0.6225 -8.988e+09 -0.6841

iter: 5  lambda: 467.0  chi2: 2107.  ratio: 0.1745
p[free]: 1.276 -1.446e+10 0.5312
dp: 0.5120 -8.100e+09 -0.5266

iter: 6  lambda: 1868.  chi2: 610.7  ratio: 0.7794
p[free]: 1.352 -9.813e+09 0.7104
dp: 0.07566 4.648e+09 0.1792

iter: 7  lambda: 933.9  chi2: 200.3  ratio: 0.9434
p[free]: 1.699 -1.019e+10 0.5279
dp: 0.3469 -3.729e+08 -0.1825

iter: 8  lambda: 467.0  chi2: 82.28  ratio: 0.9978
p[free]: 1.960 -1.003e+10 0.5124
dp: 0.2608 1.519e+08 -0.01550

iter: 9  lambda: 233.5  chi2: 79.15  ratio: 0.9919
p[free]: 2.011 -1.005e+10 0.5057
dp: 0.05114 -2.016e+07 -0.006698

iter: 10  lambda: 116.7  chi2: 79.14  ratio: 0.9970
p[free]: 2.015 -1.005e+10 0.5054
dp: 0.003616 1.233e+06 -0.0003075

iter: 11  lambda: 58.37  chi2: 79.14  ratio: 0.9513
p[free]: 2.015 -1.005e+10 0.5054
dp: 0.0001135 4.322e+04 -1.330e-05

Both ftol and xtol convergence test are satisfied
Final iter: 11  Func calls: 48  chi2: 79.14  Status: 4
Final p[free]: 2.015 -1.005e+10 0.5054

Best-fitting Parameters:
   y_max = 2.015 +/- 0.032
  x_0*a = (-1.0053 +/- 0.0092)e10
sigma_x = 0.5054 +/- 0.0092
