specular.ode.euler_scheme_2
euler_scheme_2(F, t_0, T, u_0, u_1, *, h)
Apply the explicit two-step specular Euler method of Type 2 to a scalar initial-value problem.
Parameters
| Name | Type | Description |
|---|---|---|
F |
callable | Field F(point) receiving the NumPy float64 vector [t, u] and returning a finite real scalar. |
t_0 |
real scalar | Finite initial time. |
T |
real scalar | Finite final time, strictly greater than t_0. |
u_0 |
real scalar | Finite initial value at t_0. |
u_1 |
real scalar | Finite, externally computed starting value at the first time node t[1]. |
h |
positive real scalar, keyword-only | Prescribed constant step, with 0 < h <= T - t_0. |
Returns
ODEResult: NumPy float64 arrays t and u of shape (N_h + 1,), an array sigma
of N_h ones, and the number of solver calls to F, where
N_h = floor((T - t_0)/h).
Notes
With the prescribed \(h\), \(N_h=\lfloor(T-t_0)/h\rfloor\), and \(\mathcal C=\mathcal C_1\), the recurrence is
The implementation uses the same prescribed h in every update and backward
difference. It preallocates t_n = t_0 + n*h and fills the solution row in
place, without a shortened final step. The solver keeps u_1 unchanged; with N_h=1,
it returns the two supplied values without evaluating F. The first entry
of sigma records the unscaled convention, not the caller's starter method.
Type 2 is generically first-order consistent and differs from the second-order ellipse configuration labelled SE2 on the numerical-examples page. See Type 2. Angular means use the selected backend; the outer iteration remains scalar and the stored arrays use float64.
Examples
import specular.ode
import numpy as np
def F(point):
return -point[1]
t_0, T, u_0 = 0.0, 1.0, 1.0
h = 0.01
u_1 = u_0 + h * F(np.array([t_0, u_0]))
result = specular.ode.euler_scheme_2(
F, t_0, T, u_0, u_1, h=h,
)
print(result.u[-1])
Source code in specular/ode/solver.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |