@@ -170,7 +170,7 @@ \section{BDF Methods} \label{sec:bdf}
170170\end {equation }
171171We 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 }
276276We 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
295310end
296-
311+ \end {lstlisting }
312+ Finally, we can combine them, we then have
313+ \ begin{lstlisting}
297314function 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
325326end
326327\end {lstlisting }
327328\todo [inline]{Order increase/decrease and error estimation. Maybe stiffness
0 commit comments