|
||||
File indexing completed on 2025-01-18 09:11:08
0001 // This file is part of the ACTS project. 0002 // 0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project 0004 // 0005 // This Source Code Form is subject to the terms of the Mozilla Public 0006 // License, v. 2.0. If a copy of the MPL was not distributed with this 0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/. 0008 0009 /////////////////////////////////////////////////////////////////// 0010 // RealQuadraticEquation.h, Acts project 0011 /////////////////////////////////////////////////////////////////// 0012 0013 #pragma once 0014 0015 #include <cmath> 0016 #include <utility> 0017 0018 namespace Acts::detail { 0019 0020 /// @struct RealQuadradicEquation 0021 /// Mathematic struct for solving real quadratic equations 0022 /// 0023 /// <b>Mathematical motivation</b>:<br> 0024 /// The equation is given by:<br> 0025 /// @f$ \alpha x^{2} + \beta x + \gamma = 0 @f$ 0026 /// and has therefore the analytical solution:<br> 0027 /// @f$ x_{1, 2} = - \frac{\beta \pm 0028 /// \sqrt{\beta^{2}-4\alpha\gamma}}{2\alpha}@f$ 0029 /// <br> 0030 /// <br> 0031 /// - case @f$ \beta > 0 @f$:<br> 0032 /// @f$ x_{1} = - \frac{\beta + \sqrt{\beta^{2}-4\alpha\gamma}}{2\alpha} := 0033 /// \frac{q}{\alpha}@f$, <br> 0034 /// so that @f$ q= -\frac{1}{2}(\beta+sqrt{\beta^{2}-4\alpha\gamma})@f$. 0035 /// @f$ x_{2} @f$ can now be written as: @f$ x_{2} = \frac{\gamma}{q} = 0036 /// -\frac{2\gamma}{\beta+sqrt{\beta^{2}-4\alpha\gamma}}@f$, since: <br> 0037 /// @f$ -\frac{2\gamma}{\beta+sqrt{\beta^{2}-4\alpha\gamma}} = 0038 /// -\frac{2\gamma}{\beta}\frac{1}{1+\sqrt{1-4\alpha\gamma/\beta^{2}}}@f$, and 0039 /// <br> 0040 /// @f$ x_{2}\frac{1}{1-\sqrt{1-4\alpha\gamma/\beta^{2}}} = 0041 /// -\frac{2\gamma}{\beta}\frac{1}{1-1+4\alpha\gamma/\beta^{2}}=-\frac{\beta}{2\alpha}.@f$<br> 0042 /// Hence,@f$ -\frac{\beta(1-\sqrt{1-4\alpha\gamma/\beta^{2}}}{2\alpha} = - 0043 /// \frac{\beta - \sqrt{\beta^{2}-4\alpha\gamma}}{2\alpha} @f$.<br> 0044 /// - case @f$ \beta > 0 @f$ is similar. 0045 /// 0046 0047 struct RealQuadraticEquation { 0048 double first = 0; 0049 double second = 0; 0050 int solutions = 0; 0051 0052 /// Constructor 0053 /// 0054 /// @param alpha is the first parameter of the quad equation 0055 /// @param beta is the second parameter of the quad equation 0056 /// @param gamma is the third parameter of the quad equation 0057 RealQuadraticEquation(double alpha, double beta, double gamma) { 0058 double discriminant = beta * beta - 4 * alpha * gamma; 0059 if (discriminant >= 0) { 0060 solutions = (discriminant == 0) ? 1 : 2; 0061 double q = -0.5 * (beta + (beta > 0 ? std::sqrt(discriminant) 0062 : -std::sqrt(discriminant))); 0063 first = q / alpha; 0064 second = gamma / q; 0065 } 0066 } 0067 }; 0068 0069 } // namespace Acts::detail
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |