specular.ode.euler_scheme_2
euler_scheme_2(F, t_0, T, u_0, u_1, *, n_steps)
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(t, u) 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]. |
n_steps |
positive integer, keyword-only | Number of uniform time intervals. |
Returns
ODEResult: NumPy float64 arrays t and u of shape (n_steps + 1,), an array sigma
of n_steps ones, and the number of solver calls to F.
Notes
With \(h=(T-t_0)/N\), \(N=\texttt{n_steps}\), and \(\mathcal C=\mathcal C_1\), the recurrence is
The implementation uses each represented time interval in the update and
backward difference. The solver keeps u_1 unchanged; with n_steps=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
def F(t, u):
return -u
t_0, T, u_0 = 0.0, 1.0, 1.0
n_steps = 100
h = (T - t_0) / n_steps
u_1 = u_0 + h * F(t_0, u_0)
result = specular.ode.euler_scheme_2(
F, t_0, T, u_0, u_1, n_steps=n_steps,
)
print(result.u[-1])
Source code in specular/ode/_euler.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |