14#include "../lin_alg/newton.h"
29 size_t dim = tInterval.size();
30 size_t elem_size = y0.
columns();
32 auto TOL = option.
TOL;
34 auto Jac = option.
Jac;
35 if(h == 0) { h = (tInterval[dim - 1] - tInterval[0]) / 1000.0; }
36 int n = int((tInterval[dim - 1] - tInterval[0]) / h) + 1;
40 auto y =
zeros(n, elem_size);
42 t(0, 0) = tInterval[0];
44 auto E =
eye(elem_size);
46 for(
int i = 1; i < n; ++i) {
47 auto y_act = y(i - 1).Transpose();
48 t(i, 0) = t(i - 1, 0) + h;
50 auto delta =
ones(elem_size);
51 auto prev_fun = fun(t(i - 1, 0), y_act);
53 while(
norm(delta) > TOL && k < maxIter) {
54 auto current_fun = fun(t(i, 0), y_act);
55 auto F = -1.0 * (y(i - 1).Transpose() + h / 2 * (prev_fun + current_fun) - y_act);
56 auto J = h / 2 * Jac(t(i, 0), y_act) - E;
68 return { y, t, iter };
size_t columns() const
Definition: Matrix.h:198
Matrix< double > gaussSeidel(const Matrix< double > &A, const Matrix< double > &b)
Definition: gaussSeidel.h:29
Matrix< double > eye(size_t rows, size_t columns=0)
double norm(const Matrix< double > &in)
Matrix< double > ones(size_t rows, size_t columns=1, size_t elements=1)
Matrix< double > zeros(size_t rows, size_t columns, size_t elements=1)
ODEResult ODETrapez(const ODE &fun, const std::vector< double > &tInterval, const Matrix< double > &y0, const ODEOption &option)
Definition: odeTrapez.h:28
std::function< Matrix< double >(double, Matrix< double >)> ODE
alias for ODE
Definition: ode.h:17
double TOL
tolerance for the algorithm to determine convergence
Definition: ode.h:60
int maxIter
max iterations for integrated newton steps
Definition: ode.h:62
double h
step width of t
Definition: ode.h:58
ODEJac Jac
jacobian matrix of given function
Definition: ode.h:64