# The fixed variables can be checked using the "fixednames" and # "fixedvalues" attributes of a recipe. print("free:", rec.names, "-->", rec.names) print("fixed:", rec.fixednames, "-->", rec.fixedvalues) # The fit can be rerun with a constant variable B. leastsq(rec.residual, rec.values) print(FitResults(rec)) plt.plot(linedata.x, linedata.y, 'x', linedata.x, linedata.ycalc, '-') plt.title('Line fit for variable B fixed to B=0') # <demo> --- stop --- # Fixed variables may be released with the "free" function. # free("all") releases all fixed variables. rec.free('all') # Variables may be constrained to a result of an expression. rec.constrain(rec.A, "2 * B") # Perform linear fit where slope is twice the offset. leastsq(rec.residual, rec.values) print(FitResults(rec)) plt.plot(linedata.x, linedata.y, 'x', linedata.x, linedata.ycalc, '-') plt.title('Line fit for variable A constrained to A = 2*B') # <demo> --- stop --- # Constraint expressions can be removed by calling the unconstrain function. rec.unconstrain(rec.A)
# <demo> --- stop --- # Variables defined in the recipe can be fixed to a constant value. recipe.fix(lgx0=51) # The fixed variables can be checked using the "fixednames" and # "fixedvalues" attributes of a recipe. print("free:", recipe.names, "-->", recipe.names) print("fixed:", recipe.fixednames, "-->", recipe.fixedvalues) # The fit can be rerun with a constant variable B. leastsq(recipe.residual, recipe.values) print(FitResults(recipe)) plt.plot(profile.x, profile.y, 'x', profile.x, profile.ycalc, '-') plt.title('Line fit for variable x0 fixed to x0=51') # <demo> --- stop --- # Fixed variables may be released with the "free" function. # free("all") releases all fixed variables. recipe.free('all') arst = recipe.restrain(recipe.lgx0, lb=48, ub=52, sig=0.01) # Perform fit with the line slope restrained to a maximum value of 0.2: leastsq(recipe.residual, recipe.values) print(FitResults(recipe)) plt.plot(profile.x, profile.y, 'x', profile.x, profile.ycalc, '-') plt.title('Line fit with x0 restrained to the range 48 to 52')