diff --git a/include/teqp/derivs.hpp b/include/teqp/derivs.hpp index 21ba72036606a6a58793a1b164c91d892d3f300d..d2c55ea65440ef88788037f456afad07acb2ef4b 100644 --- a/include/teqp/derivs.hpp +++ b/include/teqp/derivs.hpp @@ -15,17 +15,17 @@ derivT(const FuncType& f, TType T, const ContainerType& rho) { return f(std::complex<TType>(T, h), rho).imag() / h; } -/// Given a function, use complex step derivatives to calculate the derivative with respect to the first composition variable +/// Given a function, use complex step derivatives to calculate the derivative with respect to the given composition variable template <typename TType, typename ContainerType, typename FuncType, typename Integer> typename std::enable_if<is_container<ContainerType>::value, typename ContainerType::value_type>::type -derivrhoi(const FuncType& f, TType T, const ContainerType& rho, Integer j) { +derivrhoi(const FuncType& f, TType T, const ContainerType& rho, Integer i) { double h = 1e-100; using comtype = std::complex<ContainerType::value_type>; std::valarray<comtype> rhocom(rho.size()); - for (auto i = 0; i < rho.size(); ++i) { - rhocom[i] = comtype(rho[i], 0.0); + for (auto j = 0; j < rho.size(); ++j) { + rhocom[j] = comtype(rho[j], 0.0); } - rhocom[j] = comtype(rho[j], h); + rhocom[i] = comtype(rho[i], h); return f(T, rhocom).imag() / h; }