UserFunction in FitFunctions

Hi,

I’d like to report two things about the user defined function for the Fit algorithm.

  1. To define a power law, the UserFunction takes “^” instead of a double asterisk, which is normally used in Python. If a double asterisk is used in the function, it returns an error. There might be less confusion with " ** ".

  2. The UserFunction does not work without having “x” in it. So if I just wanted to use the UserFunction as a constant, I have to add something like “+ 0*x” in the function to make it work.

Thanks,
Koji

Hi Koji,

^ is used because the language for the userfunction string expression is muparser, not python. I’ve made a ticket for adding help text to make this clearer though, as well as improving the userfunction to be more easily used as a constant. Hope this helps.

Thanks,
Lottie

Hi Koji,

Can you use function FlatBackground in place of a constant user-function until this issue is resolved?

.Jose

Hi Lottie,

Great - thanks for making the ticket.

Koji

Hi Jose,

Thanks for the advice - I took a look at the FlatBackground option, but what I’m doing is a little more complicated. I’m doing a simultaneous fit for muSR time spectra from a field scan. Their background (or baseline) depends on the B field. Because we know exactly what the B fields are and that the background depends on the field quadratically, I’d like to set the baseline to be A0 * field^2 + A1, and fit for A0 and A1, together with other fit parameters.

Koji

If I understand your post, you need the Quadratic function to model your background while fixing the linear term to zero. You can take a look at all the fit functions and combine them to build your model.