Skip to content
Snippets Groups Projects
Unverified Commit 5fa751ee authored by Dan Nixon's avatar Dan Nixon Committed by GitHub
Browse files

Added Besselfunction (#26785)

Added Besselfunction
parents dc2782e1 ddc1b2bd
No related branches found
No related tags found
No related merge requests found
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source
# & Institut Laue - Langevin
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=invalid-name, anomalous-backslash-in-string, attribute-defined-outside-init
from mantid.api import IFunction1D, FunctionFactory
import numpy as np
from scipy import special as sp
class Bessel(IFunction1D):
def category(self):
return "Muon"
def init(self):
self.declareParameter("A0", 1, 'Amplitude')
self.declareParameter("Phi", 0.1, 'Phase(rad)')
self.declareParameter("Nu", 0.1, 'Frequency(MHz)')
def function1D(self, x):
A0 = self.getParameterValue("A0")
Phi = self.getParameterValue("Phi")
Nu = self.getParameterValue("Nu")
return A0 * sp.j0(2 * np.pi * Nu * x + Phi)
FunctionFactory.subscribe(Bessel)
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source
# & Institut Laue - Langevin
# SPDX - License - Identifier: GPL - 3.0 +
from __future__ import (absolute_import, division, print_function)
import unittest
import numpy as np
from MsdTestHelper import (is_registered, check_output, do_a_fit)
class BesselTest(unittest.TestCase):
def test_function_has_been_registered(self):
status, msg = is_registered("Bessel")
if not status:
self.fail(msg)
def test_function_output(self):
input = [0.0, 4.0, 8.0, 12.0]
expected = [0.09900249722395764, -0.010116392139648565, -0.024891569859118595, -0.006976567202361606]
tolerance = 1.0e-05
status, output = check_output("Bessel", input, expected, tolerance, A0=0.1, Phi=0.2, Nu=0.2)
if not status:
msg = 'Computed output {} from input {} unequal to expected: {}'
self.fail(msg.format(*[str(i) for i in (output, input, expected)]))
def test_do_fit(self):
do_a_fit(np.arange(0.1, 16, 0.2), 'Bessel', guess=dict(A0=0.15, Phi=0.25, Nu=0.25), target=dict(A0=0.1, Phi=0.2, Nu=0.2), atol=0.01)
if __name__ == '__main__':
unittest.main()
# Tests for Fit functions # Tests for Fit functions
set(TEST_PY_FILES set(TEST_PY_FILES
BesselTest.py
DSFinterp1DFitTest.py DSFinterp1DFitTest.py
EISFDiffSphereTest.py EISFDiffSphereTest.py
EISFDiffCylinderTest.py EISFDiffCylinderTest.py
......
.. _func-Bessel:
======
Bessel
======
.. index:: Bessel
Description
-----------
.. math:: A(t)=A_0J_0(2\pi\nu t+\phi)
where,
:math:`A_0` is the amplitude,
:math:`\nu` is the frequency of oscillation (MHz),
:math:`\phi` is the phase at :math:`t=0`,
and :math:`J_0(x)` is the Bessel Function of the first kind, its expression is given by:
.. math:: J_0(x)=\sum_{l=0}^{\infty}\frac{(-1)^l}{2^{2l}(l!)^2}x^{2l}.
.. figure:: /images/Bessel.png
:alt: A plot of Bessel function.
.. attributes::
.. properties::
References
----------
[1] `Savici et al., PRB 66 (2002) <https://journals.aps.org/prb/pdf/10.1103/PhysRevB.66.014524>`_.
.. categories::
.. sourcelink::
docs/source/images/Bessel.png

15.2 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment