Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
solve.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
19#include <cmath>
20#include <functional>
21
22namespace shammath {
23
24 template<class T>
25 float newton_rhaphson(std::function<T(T)> &&f, std::function<T(T)> &&df, T epsilon_c, T x_0) {
26
27 auto iterate_newton = [](T f, T df, T xk) -> T {
28 return xk - (f / df);
29 };
30
31 T xk = x_0;
32 T epsilon = 100000;
33
34 while (epsilon > epsilon_c) {
35 T xkp1 = iterate_newton(f(xk), df(xk), xk);
36
37 epsilon = std::fabs(xk - xkp1);
38
39 xk = xkp1;
40 }
41
42 return xk;
43 }
44
45} // namespace shammath
namespace for math utility
Definition AABB.hpp:26