File indexing completed on 2024-05-12 15:27:06

0001 /***************************************************************************
0002     File                 : nsl_diff.h
0003     Project              : LabPlot
0004     Description          : NSL numerical differentiation functions
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2016 by Stefan Gerlach (stefan.gerlach@uni.kn)
0007 
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *  This program is free software; you can redistribute it and/or modify   *
0013  *  it under the terms of the GNU General Public License as published by   *
0014  *  the Free Software Foundation; either version 2 of the License, or      *
0015  *  (at your option) any later version.                                    *
0016  *                                                                         *
0017  *  This program is distributed in the hope that it will be useful,        *
0018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0020  *  GNU General Public License for more details.                           *
0021  *                                                                         *
0022  *   You should have received a copy of the GNU General Public License     *
0023  *   along with this program; if not, write to the Free Software           *
0024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0025  *   Boston, MA  02110-1301  USA                                           *
0026  *                                                                         *
0027  ***************************************************************************/
0028 
0029 #ifndef NSL_DIFF_H
0030 #define NSL_DIFF_H
0031 
0032 #include <stdlib.h>
0033 
0034 #define NSL_DIFF_DERIV_ORDER_COUNT 6
0035 typedef enum {nsl_diff_deriv_order_first, nsl_diff_deriv_order_second, nsl_diff_deriv_order_third,
0036     nsl_diff_deriv_order_fourth, nsl_diff_deriv_order_fifth, nsl_diff_deriv_order_sixth} nsl_diff_deriv_order_type;
0037 extern const char* nsl_diff_deriv_order_name[];
0038 
0039 /************ finite differences *********/
0040 
0041 /* first derivative, central
0042     remark: do we need this?
0043 */
0044 double nsl_diff_first_central(double xm, double fm, double xp, double fp);
0045 
0046 /************ first derivatives *********/
0047 
0048 /* calculates derivative of n points of xy-data.
0049     for equal/unequal spaced data.
0050     result in y 
0051 */
0052 int nsl_diff_first_deriv_equal(const double *x, double *y, const size_t n);
0053 int nsl_diff_first_deriv(const double *x, double *y, const size_t n, int order);
0054 int nsl_diff_first_deriv_second_order(const double *x, double *y, const size_t n);
0055 int nsl_diff_first_deriv_fourth_order(const double *x, double *y, const size_t n);
0056 /* using average between left and right diff (like in other programs) */
0057 int nsl_diff_first_deriv_avg(const double *x, double *y, const size_t n);
0058 
0059 /************ second derivatives *********/
0060 
0061 /* calculates second derivative of n points of xy-data
0062     for unequal spaced data.
0063     result in y
0064 */
0065 int nsl_diff_second_deriv(const double *x, double *y, const size_t n, int order);
0066 int nsl_diff_second_deriv_first_order(const double *x, double *y, const size_t n);
0067 int nsl_diff_second_deriv_second_order(const double *x, double *y, const size_t n);
0068 int nsl_diff_second_deriv_third_order(const double *x, double *y, const size_t n);
0069 
0070 /************ third derivatives *********/
0071 
0072 /* calculates third derivative of n points of xy-data
0073     for unequal spaced data.
0074     result in y
0075 */
0076 int nsl_diff_third_deriv(const double *x, double *y, const size_t n, int order);
0077 int nsl_diff_third_deriv_second_order(const double *x, double *y, const size_t n);
0078 
0079 /************ fourth derivatives *********/
0080 
0081 /* calculates fourth derivative of n points of xy-data
0082     for unequal spaced data.
0083     result in y
0084 */
0085 int nsl_diff_fourth_deriv(const double *x, double *y, const size_t n, int order);
0086 int nsl_diff_fourth_deriv_first_order(const double *x, double *y, const size_t n);
0087 int nsl_diff_fourth_deriv_third_order(const double *x, double *y, const size_t n);
0088 
0089 /************ fifth derivatives *********/
0090 
0091 /* calculates fifth derivative of n points of xy-data
0092     for unequal spaced data.
0093     result in y
0094 */
0095 int nsl_diff_fifth_deriv(const double *x, double *y, const size_t n, int order);
0096 int nsl_diff_fifth_deriv_second_order(const double *x, double *y, const size_t n);
0097 
0098 /************ sixth derivatives *********/
0099 
0100 /* calculates sixth derivative of n points of xy-data
0101     for unequal spaced data.
0102     result in y
0103 */
0104 int nsl_diff_sixth_deriv(const double *x, double *y, const size_t n, int order);
0105 int nsl_diff_sixth_deriv_first_order(const double *x, double *y, const size_t n);
0106 
0107 #endif /* NSL_DIFF_H */