libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
cardano.h File Reference
#include <vector>
#include <cstdint>

Go to the source code of this file.

Classes

struct  InHousePolynomialSolverResult

Enumerations

enum class  CardanoResultCase : std::int8_t {
  notvalid , zerod , negatived , positived ,
  quadratic , line
}

Functions

InHousePolynomialSolverResult inHousePolynomialSolve (const std::vector< double > &polynome)

Enumeration Type Documentation

◆ CardanoResultCase

enum class CardanoResultCase : std::int8_t
strong
Enumerator
notvalid 
zerod 
negatived 
positived 
quadratic 
line 

Definition at line 35 of file cardano.h.

Function Documentation

◆ inHousePolynomialSolve()

InHousePolynomialSolverResult inHousePolynomialSolve ( const std::vector< double > & polynome)

Definition at line 115 of file cardano.cpp.

116{
119 std::size_t polynome_size = polynome.size();
120
121 double a, b, c, delta;
122
123 switch(polynome_size)
124 {
125 case 0:
126 break;
127 case 1:
128 break;
129 case 2: // linear// equation ax + b = 0
130 a = polynome[1];
131 b = polynome[0];
132 if(a != 0)
133 {
134 res.x1 = -b / a;
136 }
137 break;
138 case 3:
139 // quadratic equation ax**2 + bx + c = 0
140 a = polynome[2];
141 if(a == 0)
142 return res;
143 b = polynome[1];
144 c = polynome[0];
145
146 if(a == 0)
147 return res;
148 // calculate the discriminant
149 delta = (b * b) - (a * c * 4);
150 // qDebug() << delta;
151 if(delta < 0)
152 {
153 }
154 else if(std::abs(delta) <= 1e-20)
155 {
156 res.x1 = -b / (a * 2);
157 // qDebug() << x1.real() << " " << x2.real();
159 }
160 else
161 {
162 // find two solutions
163 delta = std::sqrt(delta);
164 res.x1 = (-b + delta) / (a * 2);
165 res.x2 = (-b - delta) / (a * 2);
166
167 // qDebug() << x1.real() << " " << x2.real();
169 }
170 break;
171 case 4:
172 cubic_solver(res, polynome[3], polynome[2], polynome[1], polynome[0]);
173 }
174 return res;
175}
void cubic_solver(InHousePolynomialSolverResult &res, double a1, double b, double c, double d)
Definition cardano.cpp:42
@ a
peak detected using a single direct MS2 observation
Definition types.h:46

References cubic_solver(), line, notvalid, and quadratic.

Referenced by pappso::MzCalibrationModel1::getMzFromTofIndex().