Skip to content

solve_vie1

solve_vie1

solve_vie1(*, kernel, g=None, continuous=False, y0=None, dt=1.0, coll_setting=None, quadrature='product', samples_per_interval=None, kernel_interp_degree=None, mesh=None, coll_nodes=None, kernel_singularity=None, reuse_adaptive_blocks=True)

Solve a Volterra integral equation of the first kind.

\[g(t) = \int_0^t K(t-s)\, y(s)\, ds, \qquad 0 \le t \le T\]

by collocation: on each mesh interval \(y\) is a polynomial that satisfies the equation at the collocation nodes.

The inputs are either arrays of samples at \(t = 0, dt, 2\,dt, \ldots\) (the sampled regime) or callables (the functional regime, solved on the breakpoints mesh); see Notes.

Parameters:

Name Type Description Default
kernel array_like or callable

\(K\). Sampled: shape (N,), or (N, d, d) for a system of \(d\) equations, at \(u = 0, dt, \ldots, (N-1)\,dt\). Callable: kernel(u) returning a scalar or a (d, d) matrix; it may be vectorised over a 1-D u, which is faster.

required
g array_like or callable

\(g\), with \(g(0) = 0\). Sampled: (N,), (N, d) or (N, d, m) for \(m\) right-hand sides. Callable: g(t) returning a scalar, (d,) or (d, m). Default zero.

None
continuous bool

Use the continuous collocation method (Brunner's \(S_m^{(0)}\), degree \(m\) on \(m\) nodes, one order higher) instead of the default discontinuous one (\(S_{m-1}^{(-1)}\)). Needs y0 and a node at the right end of each interval.

False
y0 array_like

\(y(0)\), for continuous=True only. Scalar, (d,) or (d, m).

None
dt float

Sampled inputs: the sample spacing. Default 1.0.

1.0
coll_setting int or (int, sequence of int)

Sampled inputs: the collocation nodes choices / divs as (divs, choices), with choices in 1..divs, or a bare divs meaning every point 1..divs. divs also sets the mesh width (see samples_per_interval). Default (3, [1, 2, 3]).

None
quadrature ('product', 'collocation')

Sampled inputs: how the integrals are evaluated from the samples. "product" (default) integrates a piecewise polynomial interpolant of the kernel exactly and accepts any mesh width and node set. "collocation" applies the interpolatory rule on the nodes; it is faster but fixes the mesh at divs**2 samples, runs only compiled settings (or the numba fallback), and is unstable when \(K(0)\) is small.

"product"
samples_per_interval int

Sampled inputs: samples per mesh interval. A multiple of divs with product quadrature; default divs**2, because a first-kind inversion amplifies data errors by about the inverse of the mesh width. Must be divs**2 with collocation quadrature.

None
kernel_interp_degree int

Sampled inputs, product quadrature: the degree of the kernel interpolant. Default: the number of nodes.

None
mesh array_like

Callable inputs: the mesh breakpoints, strictly increasing from 0 to \(T\). Required for callable inputs.

None
coll_nodes array_like

Callable inputs: node positions in \((0, 1]\), e.g. voles.radau_iia_nodes(3). Default [1/3, 2/3, 1].

None
kernel_singularity (float, list, dict or callable)

Callable inputs: where the kernel is weakly singular, in \(u = t - s\): a location, a list of locations, {location: alpha} for \(K \sim |u - u_0|^{-\alpha}\), or a callable returning the singular \(s\)-locations for a time \(t\). Declare the exponent when you know it: the blocks the singularity touches then use Gauss–Jacobi rules instead of adaptive quadrature, typically 3–10× faster for the whole solve.

None
reuse_adaptive_blocks bool

Callable inputs: on a uniform mesh, reuse adaptive-quadrature blocks across mesh intervals. Default True.

True

Returns:

Type Description
VolterraSolution

The solution: sol.t and sol.y on the input grid (the samples, or the mesh breakpoints), sol(t) anywhere in \([0, T]\), plus the collocation data and coefficients.

Raises:

Type Description
TypeError

An argument of the wrong type (a float where an integer is needed, a non-bool flag, a non-numeric array), or a required one missing.

ValueError

A wrong value: shapes that don't fit, an option from the other regime, a node set for which the method diverges, NaN or inf in the data, too few samples for one mesh interval.

NotImplementedError

Mixed callable and sampled inputs, or an uncompiled setting under quadrature="collocation" with no fallback.

LinAlgError

A collocation system is singular (e.g. an identically zero kernel).

Warns:

Type Description
AccuracyWarning

\(g(0) \ne 0\); a node set with \(\rho = +1\) (one order lower); \(K(0)\) too small for collocation quadrature; a singularity declared on a uniform mesh.

PerformanceWarning

The numba fallback is used; or a declared exponent in kernel_singularity failed its accuracy check, so the singular blocks used adaptive quadrature.

VolesWarning

A kernel_singularity location outside \([0, T]\).

See Also
Notes

The regime is chosen by the input types: arrays give the sampled regime (dt, coll_setting, quadrature, samples_per_interval, kernel_interp_degree apply), callables the functional regime (mesh, coll_nodes, kernel_singularity, reuse_adaptive_blocks apply). An option from the other regime is an error. Mixing callable and sampled inputs is not supported yet.

The discontinuous method converges iff its amplification factor \(\rho_m = (-1)^m \prod_{i=1}^{m} (1 - c_i)/c_i\) satisfies \(|\rho_m| \le 1\), and the continuous one iff \(\rho_{m-1} = (-1)^m \prod_{i<m} (1 - c_i)/c_i\) does, with \(c_m = 1\) (Brunner 2004, Theorems 2.4.2 and 2.4.5). The order is full for \(-1 \le \rho < 1\) and one lower at \(\rho = +1\). Radau IIA nodes have \(\rho_m = 0\); Gauss-Legendre nodes have \(\rho_m = (-1)^m\).

Examples:

Sampled data: with \(K = 1\) and \(g(t) = \sin t\) the solution is \(y = \cos t\).

>>> import numpy as np
>>> import voles
>>> t = np.linspace(0, 2, 201)
>>> sol = voles.solve_vie1(kernel=np.ones_like(t), g=np.sin(t), dt=t[1])
>>> sol
<VolterraSolution vie1, sampled, 22 intervals on [0, 2], degree 2, ...>
>>> sol.y.shape
(201,)
>>> print(f"{sol(1.0):.6f}  {np.cos(1.0):.6f}")
0.540303  0.540302

Callables: Abel's equation, \(K(u) = u^{-1/2}\) and \(g(t) = \pi t / 2\), whose solution \(y = \sqrt{t}\) has an unbounded derivative at 0. Declare the singularity and grade the mesh to match it:

>>> mesh = voles.optimal_graded_mesh(alpha=0.5, t_end=1.0, n_intervals=16, order=3)
>>> sol = voles.solve_vie1(kernel=lambda u: u**-0.5, g=lambda t: np.pi / 2 * t,
...                        mesh=mesh, kernel_singularity={0.0: 0.5})
>>> print(f"{sol(0.25):.4f}")
0.5000
Source code in src/voles/_api.py
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
def solve_vie1(*, kernel: Data, g: Optional[Data] = None, continuous: bool = False,
               y0: Optional[ArrayLike] = None,
               dt: float = 1.0, coll_setting: CollSetting = None,
               quadrature: Quadrature = "product",
               samples_per_interval: Optional[int] = None,
               kernel_interp_degree: Optional[int] = None,
               mesh: Optional[ArrayLike] = None, coll_nodes: Optional[ArrayLike] = None,
               kernel_singularity: KernelSingularity = None,
               reuse_adaptive_blocks: bool = True) -> VolterraSolution:
    r"""Solve a Volterra integral equation of the first kind.

    $$g(t) = \int_0^t K(t-s)\, y(s)\, ds, \qquad 0 \le t \le T$$

    by collocation: on each mesh interval $y$ is a polynomial that satisfies
    the equation at the collocation nodes.

    The inputs are either arrays of samples at $t = 0, dt, 2\,dt, \ldots$
    (the *sampled* regime) or callables (the *functional* regime, solved on
    the breakpoints ``mesh``); see Notes.

    Parameters
    ----------
    kernel : array_like or callable
        $K$. Sampled: shape ``(N,)``, or ``(N, d, d)`` for a system of $d$
        equations, at $u = 0, dt, \ldots, (N-1)\,dt$. Callable: ``kernel(u)``
        returning a scalar or a ``(d, d)`` matrix; it may be vectorised
        over a 1-D ``u``, which is faster.
    g : array_like or callable, optional
        $g$, with $g(0) = 0$. Sampled: ``(N,)``, ``(N, d)`` or ``(N, d, m)``
        for $m$ right-hand sides. Callable: ``g(t)`` returning a scalar,
        ``(d,)`` or ``(d, m)``. Default zero.
    continuous : bool, optional
        Use the continuous collocation method (Brunner's $S_m^{(0)}$, degree
        $m$ on $m$ nodes, one order higher) instead of the default
        discontinuous one ($S_{m-1}^{(-1)}$). Needs ``y0`` and a node at the
        right end of each interval.
    y0 : array_like, optional
        $y(0)$, for ``continuous=True`` only. Scalar, ``(d,)`` or ``(d, m)``.
    dt : float, optional
        Sampled inputs: the sample spacing. Default 1.0.
    coll_setting : int or (int, sequence of int), optional
        Sampled inputs: the collocation nodes ``choices / divs`` as
        ``(divs, choices)``, with choices in ``1..divs``, or a bare ``divs``
        meaning every point ``1..divs``. ``divs`` also sets the mesh
        width (see ``samples_per_interval``). Default ``(3, [1, 2, 3])``.
    quadrature : {"product", "collocation"}, optional
        Sampled inputs: how the integrals are evaluated from the samples.
        ``"product"`` (default) integrates a piecewise polynomial
        interpolant of the kernel exactly and accepts any mesh width and
        node set. ``"collocation"`` applies the interpolatory rule on the
        nodes; it is faster but fixes the mesh at ``divs**2`` samples, runs
        only compiled settings (or the numba fallback), and is unstable when
        $K(0)$ is small.
    samples_per_interval : int, optional
        Sampled inputs: samples per mesh interval. A multiple of ``divs``
        with product quadrature; default ``divs**2``, because a first-kind
        inversion amplifies data errors by about the inverse of the mesh
        width. Must be ``divs**2`` with collocation quadrature.
    kernel_interp_degree : int, optional
        Sampled inputs, product quadrature: the degree of the kernel
        interpolant. Default: the number of nodes.
    mesh : array_like, optional
        Callable inputs: the mesh breakpoints, strictly increasing from 0 to
        $T$. Required for callable inputs.
    coll_nodes : array_like, optional
        Callable inputs: node positions in $(0, 1]$, e.g.
        ``voles.radau_iia_nodes(3)``. Default ``[1/3, 2/3, 1]``.
    kernel_singularity : float, list, dict or callable, optional
        Callable inputs: where the kernel is weakly singular, in
        $u = t - s$: a location, a list of locations, ``{location: alpha}``
        for $K \sim |u - u_0|^{-\alpha}$, or a callable returning the
        singular $s$-locations for a time $t$. Declare the exponent when you
        know it: the blocks the singularity touches then use Gauss–Jacobi
        rules instead of adaptive quadrature, typically 3–10× faster for the
        whole solve.
    reuse_adaptive_blocks : bool, optional
        Callable inputs: on a uniform mesh, reuse adaptive-quadrature blocks
        across mesh intervals. Default True.

    Returns
    -------
    VolterraSolution
        The solution: ``sol.t`` and ``sol.y`` on the input grid (the samples,
        or the mesh breakpoints), ``sol(t)`` anywhere in $[0, T]$, plus the
        collocation data and coefficients.

    Raises
    ------
    TypeError
        An argument of the wrong type (a float where an integer is needed, a
        non-bool flag, a non-numeric array), or a required one missing.
    ValueError
        A wrong value: shapes that don't fit, an option from the other
        regime, a node set for which the method diverges, NaN or inf in
        the data, too few samples for one mesh interval.
    NotImplementedError
        Mixed callable and sampled inputs, or an uncompiled setting under
        ``quadrature="collocation"`` with no fallback.
    numpy.linalg.LinAlgError
        A collocation system is singular (e.g. an identically zero kernel).

    Warns
    -----
    AccuracyWarning
        $g(0) \ne 0$; a node set with $\rho = +1$ (one order lower);
        $K(0)$ too small for collocation quadrature; a singularity declared
        on a uniform mesh.
    PerformanceWarning
        The numba fallback is used; or a declared exponent in
        ``kernel_singularity`` failed its accuracy check, so the singular
        blocks used adaptive quadrature.
    VolesWarning
        A ``kernel_singularity`` location outside $[0, T]$.

    See Also
    --------
    - [solve_vie2][voles.solve_vie2], [solve_vide][voles.solve_vide]: the other two
      equations.
    - [VolterraSolution][voles.VolterraSolution]: the returned object.
    - [optimal_graded_mesh][voles.optimal_graded_mesh]: a mesh for a weakly singular
      kernel.
    - [radau_iia_nodes][voles.radau_iia_nodes]: node sets for ``coll_nodes``.

    Notes
    -----
    The regime is chosen by the input types: arrays give the sampled regime
    (``dt``, ``coll_setting``, ``quadrature``, ``samples_per_interval``,
    ``kernel_interp_degree`` apply), callables the functional regime
    (``mesh``, ``coll_nodes``, ``kernel_singularity``,
    ``reuse_adaptive_blocks`` apply). An option from the other regime is
    an error. Mixing callable and sampled inputs is not supported yet.

    The discontinuous method converges iff its amplification factor
    $\rho_m = (-1)^m \prod_{i=1}^{m} (1 - c_i)/c_i$ satisfies
    $|\rho_m| \le 1$, and the continuous one iff
    $\rho_{m-1} = (-1)^m \prod_{i<m} (1 - c_i)/c_i$ does, with $c_m = 1$
    (Brunner 2004, Theorems 2.4.2 and 2.4.5). The order is full for
    $-1 \le \rho < 1$ and one lower at $\rho = +1$. Radau IIA nodes have
    $\rho_m = 0$; Gauss-Legendre nodes have $\rho_m = (-1)^m$.

    Examples
    --------
    Sampled data: with $K = 1$ and $g(t) = \sin t$ the solution is
    $y = \cos t$.

    >>> import numpy as np
    >>> import voles
    >>> t = np.linspace(0, 2, 201)
    >>> sol = voles.solve_vie1(kernel=np.ones_like(t), g=np.sin(t), dt=t[1])
    >>> sol
    <VolterraSolution vie1, sampled, 22 intervals on [0, 2], degree 2, ...>
    >>> sol.y.shape
    (201,)
    >>> print(f"{sol(1.0):.6f}  {np.cos(1.0):.6f}")
    0.540303  0.540302

    Callables: Abel's equation, $K(u) = u^{-1/2}$ and $g(t) = \pi t / 2$,
    whose solution $y = \sqrt{t}$ has an unbounded derivative at 0. Declare
    the singularity and grade the mesh to match it:

    >>> mesh = voles.optimal_graded_mesh(alpha=0.5, t_end=1.0, n_intervals=16, order=3)
    >>> sol = voles.solve_vie1(kernel=lambda u: u**-0.5, g=lambda t: np.pi / 2 * t,
    ...                        mesh=mesh, kernel_singularity={0.0: 0.5})
    >>> print(f"{sol(0.25):.4f}")
    0.5000
    """
    return _solve("vie1", kernel=kernel, g=g, y0=y0, continuous=continuous, dt=dt,
                  coll_setting=coll_setting, quadrature=quadrature,
                  samples_per_interval=samples_per_interval,
                  kernel_interp_degree=kernel_interp_degree, mesh=mesh, coll_nodes=coll_nodes,
                  kernel_singularity=kernel_singularity,
                  reuse_adaptive_blocks=reuse_adaptive_blocks)