IAP GITLAB

quartic.h 3 KB
Newer Older
Andre Schmidt's avatar
Test  
Andre Schmidt committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/***************************************************************************
 *   Copyright (C) 2016 by Саша Миленковић                                 *
 *   sasa.milenkovic.xyz@gmail.com                                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *   ( http://www.gnu.org/licenses/gpl-3.0.en.html )                       *
 *									   *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
 
#ifndef QUARTIC_H_INCLUDED
#define QUARTIC_H_INCLUDED

#include <complex>

const double PI = 3.141592653589793238463L;
const double M_2PI = 2*PI;
const double eps=1e-12;

typedef std::complex<double> DComplex;

//---------------------------------------------------------------------------
// useful for testing
 inline DComplex polinom_2(DComplex x, double a, double b)
 {
	 //Horner's scheme for x*x + a*x + b
	 return x * (x + a) + b;
 }

//---------------------------------------------------------------------------
// useful for testing
 inline DComplex polinom_3(DComplex x, double a, double b, double c)
 {
	 //Horner's scheme for x*x*x + a*x*x + b*x + c;
	 return x * (x * (x + a) + b) + c;
 }

//---------------------------------------------------------------------------
// useful for testing
 inline DComplex polinom_4(DComplex x, double a, double b, double c, double d)
 {
	 //Horner's scheme for x*x*x*x + a*x*x*x + b*x*x + c*x + d;
	 return x * (x * (x * (x + a) + b) + c) + d;
 }

//---------------------------------------------------------------------------
// x - array of size 3
// In case 3 real roots: => x[0], x[1], x[2], return 3
//         2 real roots: x[0], x[1],          return 2
//         1 real root : x[0], x[1] ± i*x[2], return 1
unsigned int solveP3(double* x, double a, double b, double c);

//---------------------------------------------------------------------------
// solve quartic equation x^4 + a*x^3 + b*x^2 + c*x + d
// Attention - this function returns dynamically allocated array. It has to be released afterwards.
DComplex* solve_quartic(double a, double b, double c, double d);


#endif // QUARTIC_H_INCLUDED