\(\renewcommand\AA{\unicode{x212B}}\)

Exercise 5

The aim of this exercise is to implement a simple linear fitting function defined as:

\[\LARGE y = A_0 + A_1x\]

The function should have 2 parameters:

  1. A0: intercept with the y-axis.

  2. A1: gradient of the function.

Define a class called PyLinearFunction

  • Add an init function that declares the two parameters.

  • Add a function1D function that returns the y values for the given x values as a numpy array.

  • Add the appropriate line to register it with Mantid.

To test:

  1. Execute your code in the script window to register the function with Mantid.

  2. Load file GEM38370_Focussed_Legacy.nxs.

  3. Plot spectrum number 5.

  4. Activate the fitting tool.

  5. Right click on the plot and select “Add Other Function…”.

  6. Select PyLinearFunction.

  7. Change StartX to 0.1 and EndX to 2.0

  8. Click Fit!

Once finished check your answer with the provided Exercise 5 Solutions