File indexing completed on 2024-05-12 03:47:50

0001 /*
0002     File                 : nsl_diff.h
0003     Project              : LabPlot
0004     Description          : NSL numerical differentiation functions
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2016 Stefan Gerlach <stefan.gerlach@uni.kn>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef NSL_DIFF_H
0011 #define NSL_DIFF_H
0012 
0013 #include <stdlib.h>
0014 
0015 #define NSL_DIFF_DERIV_ORDER_COUNT 6
0016 typedef enum {
0017     nsl_diff_deriv_order_first,
0018     nsl_diff_deriv_order_second,
0019     nsl_diff_deriv_order_third,
0020     nsl_diff_deriv_order_fourth,
0021     nsl_diff_deriv_order_fifth,
0022     nsl_diff_deriv_order_sixth
0023 } nsl_diff_deriv_order_type;
0024 extern const char* nsl_diff_deriv_order_name[];
0025 
0026 /************ finite differences *********/
0027 
0028 /* first derivative, central
0029     remark: do we need this?
0030 */
0031 double nsl_diff_first_central(double xm, double fm, double xp, double fp);
0032 
0033 /************ first derivatives *********/
0034 
0035 /* calculates derivative of n points of xy-data.
0036     for equal/unequal spaced data.
0037     result in y
0038 */
0039 int nsl_diff_first_deriv_equal(const double* x, double* y, const size_t n);
0040 int nsl_diff_first_deriv(const double* x, double* y, const size_t n, int order);
0041 int nsl_diff_first_deriv_second_order(const double* x, double* y, const size_t n);
0042 int nsl_diff_first_deriv_fourth_order(const double* x, double* y, const size_t n);
0043 /* using average between left and right diff (like in other programs) */
0044 int nsl_diff_first_deriv_avg(const double* x, double* y, const size_t n);
0045 
0046 /************ second derivatives *********/
0047 
0048 /* calculates second derivative of n points of xy-data
0049     for unequal spaced data.
0050     result in y
0051 */
0052 int nsl_diff_second_deriv(const double* x, double* y, const size_t n, int order);
0053 int nsl_diff_second_deriv_first_order(const double* x, double* y, const size_t n);
0054 int nsl_diff_second_deriv_second_order(const double* x, double* y, const size_t n);
0055 int nsl_diff_second_deriv_third_order(const double* x, double* y, const size_t n);
0056 
0057 /************ third derivatives *********/
0058 
0059 /* calculates third derivative of n points of xy-data
0060     for unequal spaced data.
0061     result in y
0062 */
0063 int nsl_diff_third_deriv(const double* x, double* y, const size_t n, int order);
0064 int nsl_diff_third_deriv_second_order(const double* x, double* y, const size_t n);
0065 
0066 /************ fourth derivatives *********/
0067 
0068 /* calculates fourth derivative of n points of xy-data
0069     for unequal spaced data.
0070     result in y
0071 */
0072 int nsl_diff_fourth_deriv(const double* x, double* y, const size_t n, int order);
0073 int nsl_diff_fourth_deriv_first_order(const double* x, double* y, const size_t n);
0074 int nsl_diff_fourth_deriv_third_order(const double* x, double* y, const size_t n);
0075 
0076 /************ fifth derivatives *********/
0077 
0078 /* calculates fifth derivative of n points of xy-data
0079     for unequal spaced data.
0080     result in y
0081 */
0082 int nsl_diff_fifth_deriv(const double* x, double* y, const size_t n, int order);
0083 int nsl_diff_fifth_deriv_second_order(const double* x, double* y, const size_t n);
0084 
0085 /************ sixth derivatives *********/
0086 
0087 /* calculates sixth derivative of n points of xy-data
0088     for unequal spaced data.
0089     result in y
0090 */
0091 int nsl_diff_sixth_deriv(const double* x, double* y, const size_t n, int order);
0092 int nsl_diff_sixth_deriv_first_order(const double* x, double* y, const size_t n);
0093 
0094 #endif /* NSL_DIFF_H */