yat/utility/univariable/df.h

Code
Comments
Other
Rev Date Author Line
4238 18 Sep 22 peter 1 #ifndef theplu_yat_utility_univariable_df
4238 18 Sep 22 peter 2 #define theplu_yat_utility_univariable_df
4237 17 Sep 22 peter 3
4237 17 Sep 22 peter 4 // $Id$
4237 17 Sep 22 peter 5
4237 17 Sep 22 peter 6 /*
4237 17 Sep 22 peter 7   Copyright (C) 2022 Peter Johansson
4237 17 Sep 22 peter 8
4237 17 Sep 22 peter 9   This file is part of the yat library, http://dev.thep.lu.se/yat
4237 17 Sep 22 peter 10
4237 17 Sep 22 peter 11   The yat library is free software; you can redistribute it and/or
4237 17 Sep 22 peter 12   modify it under the terms of the GNU General Public License as
4237 17 Sep 22 peter 13   published by the Free Software Foundation; either version 3 of the
4237 17 Sep 22 peter 14   License, or (at your option) any later version.
4237 17 Sep 22 peter 15
4237 17 Sep 22 peter 16   The yat library is distributed in the hope that it will be useful,
4237 17 Sep 22 peter 17   but WITHOUT ANY WARRANTY; without even the implied warranty of
4237 17 Sep 22 peter 18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4237 17 Sep 22 peter 19   General Public License for more details.
4237 17 Sep 22 peter 20
4237 17 Sep 22 peter 21   You should have received a copy of the GNU General Public License
4237 17 Sep 22 peter 22   along with yat. If not, see <https://www.gnu.org/licenses/>.
4237 17 Sep 22 peter 23 */
4237 17 Sep 22 peter 24
4237 17 Sep 22 peter 25 namespace theplu {
4237 17 Sep 22 peter 26 namespace yat {
4237 17 Sep 22 peter 27 namespace utility {
4237 17 Sep 22 peter 28
4237 17 Sep 22 peter 29   namespace univariable
4237 17 Sep 22 peter 30   {
4238 18 Sep 22 peter 31     template<class FUNC>
4238 18 Sep 22 peter 32     double df(double x, void* params)
4238 18 Sep 22 peter 33     {
4238 18 Sep 22 peter 34       FUNC* func = static_cast<FUNC*>(params);
4239 18 Sep 22 peter 35       return func->derivative(x);
4238 18 Sep 22 peter 36     }
4238 18 Sep 22 peter 37
4238 18 Sep 22 peter 38     template<class FUNC>
4238 18 Sep 22 peter 39     void fdf(double x, void* params, double* f, double* df)
4238 18 Sep 22 peter 40     {
4238 18 Sep 22 peter 41       FUNC* func = static_cast<FUNC*>(params);
4238 18 Sep 22 peter 42       *f = (*func)(x);
4239 18 Sep 22 peter 43       *df = func->derivative(x);
4238 18 Sep 22 peter 44     }
4237 17 Sep 22 peter 45   } // end namespace univariable
4237 17 Sep 22 peter 46
4237 17 Sep 22 peter 47 }}} // end namespaces utility, yat and theplu
4237 17 Sep 22 peter 48 #endif