KrisLibrary  1.0.0
diffeq.h
Go to the documentation of this file.
1 #ifndef MATH_DIFFEQ_H
2 #define MATH_DIFFEQ_H
3 
4 #include "function.h"
5 
11 namespace Math {
14 
24 Real RungeKutta4_step(RealFunction2* f, Real t0, Real h, Real w);
25 
35 Real RungeKutta4(RealFunction2* f, Real a, Real b, Real alpha, int n);
36 
47 Real RKF(RealFunction2* f, Real a, Real b, Real alpha, Real tol, Real hmax, Real hmin);
48 
53 Real AM2I(RealFunction2* f, Real h, Real t0, Real t1, Real t2, Real w0, Real w1, Real w2);
54 
59 Real AM2E(RealFunction2* f, Real h, Real t0, Real t1, Real w0, Real w1);
60 
61 /*
62 function w2 = AM2_implicit_step(f, df, h, t0, t1, t2, w0, w1)
63  //define a function j with a root at w2
64  f1 = f(t1,w1);
65  f0 = f(t0,w0);
66  function y = j(w)
67  y = w1 + h/12*(5*f(t2,w) + 8*f1 - f0) - w;
68  endfunction
69  //define dj = j'
70  function y = dj(w)
71  y = h/12*(5*df(t2,w)) - 1;
72  endfunction
73  function y = g(w)
74  y = w - j(w)/dj(w);
75  endfunction
76 
77  //perform newton iteration, tol 10^-4, max 10 steps
78  //w2 = newton(j,dj,w1, 1e-4,10);
79  w2 = fixed_point(g,w1,1e-5,10);
80 endfunction
81 */
82 
84 Real AM2_predictor_corrector_step(RealFunction2* f, Real h, Real t0, Real t1, Real t2, Real w0, Real w1);
85 
86 /*
87 W = AM2_implicit(RealFunction* f, RealFunction* df, Real a, Real b, Real alpha0, Real alpha1, int n)
88 {
89  h = (b-a)/n;
90  W(1) = alpha0;
91  W(2) = alpha1;
92  t = a + 2*h;
93  for i=2:n
94  W(i+1) = AM2_implicit_step(f,df, h, t-h,t,t+h, W(i-1), W(i));
95  end
96 }
97 */
98 
100 Real AM2_predictor_corrector(RealFunction2* f, Real a, Real b, Real alpha0, Real alpha1, int n);
101 
102 
103 
105 
106 
116 void Euler_step(DiffEqFunction* f, Real t0, Real h, const Vector& w0, Vector& w1);
117 
127 void RungeKutta4_step(DiffEqFunction* f, Real t0, Real h, const Vector& w0, Vector& w1);
128 
138 void Euler(DiffEqFunction* f, Real a, Real b, const Vector& alpha, int n, Vector& wn);
139 
149 void RungeKutta4(DiffEqFunction* f, Real a, Real b, const Vector& alpha, int n, Vector& wn);
150 
152 }//namespace Math
153 #endif
Abstract base classes for function interfaces.
Real AM2_predictor_corrector(RealFunction2 *f, Real a, Real b, Real alpha0, Real alpha1, int n)
Adams-Moulton predictor-corrector of order 2 for 1D ODEs.
Definition: diffeq.cpp:174
Real AM2E(RealFunction2 *f, Real h, Real t0, Real t1, Real w0, Real w1)
Adams-Bashforth 2 step explicit method for 1D ODEs.
Definition: diffeq.cpp:125
Real AM2I(RealFunction2 *f, Real h, Real t0, Real t1, Real t2, Real w0, Real w1, Real w2)
Adams-Moulton 2 step implicit method for 1D ODEs.
Definition: diffeq.cpp:118
Real RungeKutta4(RealFunction2 *f, Real a, Real b, Real alpha, int n)
Runge-Kutta 4 method for 1D ODEs.
Definition: diffeq.cpp:26
void Euler(DiffEqFunction *f, Real a, Real b, const Vector &alpha, int n, Vector &wn)
Solve an ODE system using Euler's method.
Definition: diffeq.cpp:247
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12
Real RKF(RealFunction2 *f, Real a, Real b, Real alpha, Real tol, Real hmax, Real hmin)
Runge-Kutta-Fehlberg method for 1D ODEs.
Definition: diffeq.cpp:46
Real AM2_predictor_corrector_step(RealFunction2 *f, Real h, Real t0, Real t1, Real t2, Real w0, Real w1)
Adams-Moulton predictor-corrector step of order 2 for 1D ODEs.
Definition: diffeq.cpp:153
void Euler_step(DiffEqFunction *f, Real t0, Real h, const Vector &w0, Vector &w1)
Euler step for an ODE system.
Definition: diffeq.cpp:205
Real RungeKutta4_step(RealFunction2 *f, Real t0, Real h, Real w)
Runge-Kutta 4 step for 1D ODEs.
Definition: diffeq.cpp:12