Learn R Programming

comphy (version 1.0.5)

EPSturmLiouville2: Sturm–Liouville eigenproblem with homogeneous Dirichlet boundary conditions

Description

Solves $$-\frac{d}{dx}\left(p(x)\,y'(x)\right) + q(x)\,y(x) = \lambda\, w(x)\,y(x)$$ on \([a,b]\) with \(y(a)=0\) and \(y(b)=0\). The equation is discretised on the interior nodes of a uniform grid and assembled into matrices K and W so that K u = lambda W u. The problem is reduced to a symmetric standard eigenproblem and solved.

Usage

EPSturmLiouville2(
  p,
  q,
  w,
  x,
  nev = NULL,
  normalize = TRUE,
  return_matrices = FALSE,
  check_inputs = TRUE,
  tol_uniform = 1e-12
)

Value

A list with

  • values: eigenvalues (ascending).

  • vectors_interior: interior eigenvectors (matrix (n-1) x k).

  • vectors_full: full eigenfunctions with zero endpoints (matrix (n+1) x k).

  • x, h, nev_used.

  • K, W if return_matrices=TRUE.

Arguments

p

Function p(x) or numeric vector at midpoints.

q

Function q(x) or numeric vector at nodes.

w

Function w(x) or numeric vector at nodes.

x

Numeric grid including endpoints (x[1]=a, x[n+1]=b); must be uniform.

nev

Integer number of eigenpairs to return (smallest); default all interior modes.

normalize

Logical; if TRUE, scale interior eigenvectors so that \(\sum_i h\,w_i\,u_i^2 = 1\). Default TRUE.

return_matrices

Logical; if TRUE, also return K and W. Default FALSE.

check_inputs

Logical; run basic checks (uniform grid, positivity of p, w). Default TRUE.

tol_uniform

Tolerance for uniform‑grid check. Default 1e-12.

Details

Coefficients may be given as functions or numeric vectors:

  • p: function on midpoints or numeric vector of length length(x)-1 (midpoints).

  • q, w: functions on nodes or numeric vectors of length length(x) (nodes).

Homogeneous Dirichlet conditions are enforced by construction: unknowns are interior only; the returned full eigenfunctions have zero endpoints.

Examples

Run this code
# p=1, q=0, w=1 on [0, pi]  -> eigenvalues ~ 1^2, 2^2, 3^2, ...
a <- 0; b <- pi; n <- 200
x <- seq(a, b, length.out = n+1)
pfun <- function(s) 1            # scalars are accepted; will be replicated
qfun <- function(s) 0
wfun <- function(s) 1
ep <- EPSturmLiouville2(pfun, qfun, wfun, x, nev = 4, normalize = TRUE)
round(ep$values, 3)              # ~ c(1, 4, 9, 16)

Run the code above in your browser using DataLab