Skip to content

Commit c0c957a

Browse files
committed
Restructure code
1 parent f60b314 commit c0c957a

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

nordsieck/nordsieck.tex

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ \section{BDF Methods} \label{sec:bdf}
170170
\end{equation}
171171
We have
172172
\begin{align}
173-
\Lambda_n(x) &= \Pi_{i=1}^q (1+\frac{x}{\Xi_i}) = \sum_{j=1}{q+1}l_jx^j, \quad x=\frac{t-t_n}{h},\;
173+
\Lambda_n(x) &= \Pi_{i=1}^q (1+\frac{x}{\Xi_i}) = \sum_{j=0}^{q}l_jx^{j}, \quad x=\frac{t-t_n}{h},\;
174174
\Xi_i = \frac{t_n-t_{n-i}}{h} \\
175175
\Delta_n(t) &= \Delta_n(t_n+hx) = \Delta_n(x)e_n.
176176
\end{align}
@@ -270,8 +270,8 @@ \section{Adams Methods} \label{sec:adams}
270270
\begin{equation}
271271
\Lambda_n(x) = \frac{\int_{-1}^x\prod_{i=1}^{q-1} (u+\Xi_i) \dd{u}}
272272
{\underbrace{\int_{-1}^0\prod_{i=1}^{q-1} (u+\Xi_i)
273-
\dd{u}}_\text{constant}}
274-
= \sum_{j=1}^{q+1} l_jx^j.
273+
\dd{u}}_\text{constant normalization}}
274+
= \sum_{j=0}^{q} l_jx^j.
275275
\end{equation}
276276
We can compute the vector $l_j$ by first calculating the coefficients of
277277
$\prod_{i=1}^{q-1} (u+\Xi_i)$ and integrate it with some normalization. Here is
@@ -280,7 +280,22 @@ \section{Adams Methods} \label{sec:adams}
280280
\sum_{1\leq i_{1}<i_{2}<\cdots <i_{k}\leq n}x_{i_{1}}x_{i_{2}}\cdots
281281
x_{i_{k}}=(-1)^{k}l_{n-k},
282282
\end{equation}
283-
where $x_j$ is the $j$-th roots of a polynomial.
283+
where $x_j$ is the $j$-th roots of a polynomial. Here is the Julia
284+
implementation for computing $\int_{-1}^x\prod_{i=1}^{q-1} (u+\Xi_i) \dd{u} =
285+
\sum_{i=1}^{q-1} m_ix^i$.
286+
\begin{lstlisting}
287+
# compute coefficients from the Newton polynomial
288+
m[1] = ONE
289+
for j in 1:order-1
290+
Xi_inv = dt / dtsum
291+
for i in j:-1:1
292+
m[i+1] += m[i] * Xi_inv
293+
end
294+
dtsum += tau[j+1]
295+
end
296+
\end{lstlisting}
297+
Next, we need to have a routine to integrate the coefficients of this
298+
polynomial. The implementation reads
284299
\begin{lstlisting}
285300
# This function computes the integral, from -1 to 0, of a polynomial
286301
# `P(x)` from the coefficients of `P` with an offset `k`.
@@ -293,35 +308,21 @@ \section{Adams Methods} \label{sec:adams}
293308
end
294309
return int
295310
end
296-
311+
\end{lstlisting}
312+
Finally, we can combine them, we then have
313+
\begin{lstlisting}
297314
function calc_coeff!(cache::T) where T
298315
@unpack m, l, tau = cache
299316
ZERO, ONE = zero(m[1]), one(m[1])
300317
dtsum = dt = tau[1]
301318
order = cache.step
302-
m[1] = ONE
303-
for i in 2:order+1
304-
m[i] = ZERO
305-
end
306-
# initialize Xi_inv
307-
Xi_inv = dt / dtsum
308-
# compute coefficients from the Newton polynomial
309-
for j in 1:order-1
310-
Xi_inv = dt / dtsum
311-
for i in j:-1:1
312-
m[i+1] += m[i] * Xi_inv
313-
end
314-
dtsum += tau[j+1]
315-
end
316-
319+
# normalization
317320
M0 = int01dx(m, order, 0)
318-
M1 = int01dx(m, order, 1)
319321
M0_inv = inv(M0)
320322
l[1] = ONE
321323
for i in 1:order
322324
l[i+1] = M0_inv * m[i] / i
323325
end
324-
cache.tq = M1 * M0_inv * Xi_inv
325326
end
326327
\end{lstlisting}
327328
\todo[inline]{Order increase/decrease and error estimation. Maybe stiffness

0 commit comments

Comments
 (0)