Tatooine
newton_raphson.h
Go to the documentation of this file.
1#ifndef TATOOINE_NEWTON_RAPHSON_H
2#define TATOOINE_NEWTON_RAPHSON_H
3
4#include "symbolic_field.h"
5#include "diff.h"
6
7//==============================================================================
8namespace tatooine {
9//==============================================================================
10
11template <typename Real, size_t N, size_t... Is>
12[[nodiscard]] auto newton_raphson(const symbolic::field<Real, N, N>& v,
14 Real t, size_t n, double precision,
15 std::index_sequence<Is...>) {
16 auto Jv = diff(v);
17 auto step = vec<GiNaC::ex, N>{v.x(Is)...} - inverse(Jv.expr()) * v.expr();
18
19 for (size_t i = 0; i < n; ++i) {
20 auto y = evtod<Real>(step, (v.x(Is) == x(Is))..., v.t() == t);
21 if (distance(x, y) < precision) {
22 x = std::move(y);
23 break;
24 };
25 x = std::move(y);
26 }
27 return x;
28}
29// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30template <typename Real, size_t N>
31[[nodiscard]] auto newton_raphson(const symbolic::field<Real, N, N>& v,
33 Real t, size_t n, double precision = 1e-10) {
34 return newton_raphson(v, x, t, n, precision, std::make_index_sequence<N>{});
35}
36
37//==============================================================================
38} // namespace tatooine
39//==============================================================================
40
41#endif
Definition: algorithm.h:6
constexpr auto distance(Iter const &it0, Iter const &it1)
Definition: iterator_facade.h:372
auto newton_raphson(const symbolic::field< Real, N, N > &v, typename symbolic::field< Real, N, N >::pos_type x, Real t, size_t n, double precision, std::index_sequence< Is... >)
Definition: newton_raphson.h:12
auto inverse(const base_tensor< Tensor, GiNaC::ex, M, N > &m_in)
Definition: tensor_symbolic.h:81
constexpr auto diff(polynomial< Real, Degree > const &f)
Definition: polynomial.h:179
Definition: symbolic_field.h:16
auto expr() const -> const auto &
Definition: symbolic_field.h:39
static auto x(size_t i) -> auto &
Definition: symbolic_field.h:24
static auto t() -> auto &
Definition: symbolic_field.h:25
Definition: vec.h:12