d02 Chapter Contents
d02 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_ode_bvp_ps_lin_solve (d02uec)

## 1  Purpose

nag_ode_bvp_ps_lin_solve (d02uec) finds the solution of a linear constant coefficient boundary value problem by using the Chebyshev integration formulation on a Chebyshev Gauss–Lobatto grid.

## 2  Specification

 #include #include
 void nag_ode_bvp_ps_lin_solve (Integer n, double a, double b, Integer m, const double c[], double bmat[], const double y[], const double bvec[], double f[], double uc[], double *resid, NagError *fail)

## 3  Description

nag_ode_bvp_ps_lin_solve (d02uec) solves the constant linear coefficient ordinary differential problem
 $∑ j=0 m fj+1 dju dxj = fx , x ∈ a,b$
subject to a set of $m$ linear constraints at points ${y}_{\mathit{i}}\in \left[a,b\right]$, for $\mathit{i}=1,2,\dots ,m$:
 $∑ j=0 m B i,j+1 dju dxj x=yi = βi ,$
where $1\le m\le 4$, $B$ is an $m×\left(m+1\right)$ matrix of constant coefficients and ${\beta }_{i}$ are constants. The points ${y}_{i}$ are usually either $a$ or $b$.
The function $f\left(x\right)$ is supplied as an array of Chebyshev coefficients ${c}_{j}$, $j=0,1,\dots ,n$ for the function discretized on $n+1$ Chebyshev Gauss–Lobatto points (as returned by nag_ode_bvp_ps_lin_cgl_grid (d02ucc)); the coefficients are normally obtained by a previous call to nag_ode_bvp_ps_lin_coeffs (d02uac). The solution and its derivatives (up to order $m$) are returned, in the form of their Chebyshev series representation, as arrays of Chebyshev coefficients; subsequent calls to nag_ode_bvp_ps_lin_cgl_vals (d02ubc) will return the corresponding function and derivative values at the Chebyshev Gauss–Lobatto discretization points on $\left[a,b\right]$. Function and derivative values can be obtained on any uniform grid over the same range $\left[a,b\right]$ by calling the interpolation function nag_ode_bvp_ps_lin_grid_vals (d02uwc).
Clenshaw C W (1957) The numerical solution of linear differential equations in Chebyshev series Proc. Camb. Phil. Soc. 53 134–149
Coutsias E A, Hagstrom T and Torres D (1996) An efficient spectral method for ordinary differential equations with rational function coefficients Mathematics of Computation 65(214) 611–635
Greengard L (1991) Spectral integration and two-point boundary value problems SIAM J. Numer. Anal. 28(4) 1071–80
Lundbladh A, Hennigson D S and Johannson A V (1992) An efficient spectral integration method for the solution of the Navier–Stokes equations Technical report FFA–TN 1992–28 Aeronautical Research Institute of Sweden
Muite B K (2010) A numerical comparison of Chebyshev methods for solving fourth-order semilinear initial boundary value problems Journal of Computational and Applied Mathematics 234(2) 317–342

## 5  Arguments

1:    $\mathbf{n}$IntegerInput
On entry: $n$, where the number of grid points is $n+1$.
Constraint: ${\mathbf{n}}\ge 8$ and n is even.
2:    $\mathbf{a}$doubleInput
On entry: $a$, the lower bound of domain $\left[a,b\right]$.
Constraint: ${\mathbf{a}}<{\mathbf{b}}$.
3:    $\mathbf{b}$doubleInput
On entry: $b$, the upper bound of domain $\left[a,b\right]$.
Constraint: ${\mathbf{b}}>{\mathbf{a}}$.
4:    $\mathbf{m}$IntegerInput
On entry: the order, $m$, of the boundary value problem to be solved.
Constraint: $1\le {\mathbf{m}}\le 4$.
5:    $\mathbf{c}\left[{\mathbf{n}}+1\right]$const doubleInput
On entry: the Chebyshev coefficients ${c}_{j}$, $j=0,1,\dots ,n$, for the right hand side of the boundary value problem. Usually these are obtained by a previous call of nag_ode_bvp_ps_lin_coeffs (d02uac).
6:    $\mathbf{bmat}\left[{\mathbf{m}}×\left({\mathbf{m}}+1\right)\right]$doubleInput/Output
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{bmat}}\left[\left(j-1\right)×{\mathbf{m}}+i-1\right]$.
On entry: ${\mathbf{bmat}}\left[\mathit{j}×{\mathbf{m}}+\mathit{i}-1\right]$ must contain the coefficients ${B}_{\mathit{i},\mathit{j}+1}$, for $\mathit{i}=1,2,\dots ,m$ and $\mathit{j}=0,1,\dots ,m$, in the problem formulation of Section 3.
On exit: the coefficients have been scaled to form an equivalent problem defined on the domain $\left[-1,1\right]$.
7:    $\mathbf{y}\left[{\mathbf{m}}\right]$const doubleInput
On entry: the points, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,m$, where the boundary conditions are discretized.
8:    $\mathbf{bvec}\left[{\mathbf{m}}\right]$const doubleInput
On entry: the values, ${\beta }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,m$, in the formulation of the boundary conditions given in Section 3.
9:    $\mathbf{f}\left[{\mathbf{m}}+1\right]$doubleInput/Output
On entry: the coefficients, ${f}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,m+1$, in the formulation of the linear boundary value problem given in Section 3. The highest order term, ${\mathbf{f}}\left[{\mathbf{m}}\right]$, needs to be nonzero to have a well posed problem.
On exit: the coefficients have been scaled to form an equivalent problem defined on the domain $\left[-1,1\right]$.
10:  $\mathbf{uc}\left[\left({\mathbf{n}}+1\right)×\left({\mathbf{m}}+1\right)\right]$doubleOutput
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{uc}}\left[\left(j-1\right)×\left({\mathbf{n}}+1\right)+i-1\right]$.
On exit: the Chebyshev coefficients in the Chebyshev series representations of the solution and derivatives of the solution to the boundary value problem. The coefficients of $U$ are stored as the first $n+1$ elements of uc, the first derivative coefficients are stored as the next $n+1$ elements of uc, and so on.
11:  $\mathbf{resid}$double *Output
On exit: the maximum residual resulting from substituting the solution vectors returned in uc into both linear equations of Section 3 representing the linear boundary value problem and associated boundary conditions. That is
 $max max i=1,m ∑ j=0 m B i,j+1 dju dxj x=yi - βi , max i=1, n+1 ∑ j=0 m f j+1 dju dxj x=xi - fx .$
12:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_CONVERGENCE
During iterative refinement, convergence was achieved, but the residual is more than . $\text{Residual achieved on convergence}=〈\mathit{\text{value}}〉$.
NE_INT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{m}}\le 4$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: n is even.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 8$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Internal error while unpacking matrix during iterative refinement.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_REAL_2
On entry, ${\mathbf{a}}=〈\mathit{\text{value}}〉$ and ${\mathbf{b}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{a}}<{\mathbf{b}}$.
NE_REAL_ARRAY
On entry, ${\mathbf{f}}\left[{\mathbf{m}}\right]=0.0$.
NE_SINGULAR_MATRIX
Singular matrix encountered during iterative refinement.
NE_TOO_MANY_ITER
During iterative refinement, the maximum number of iterations was reached.
$\text{Number of iterations}=〈\mathit{\text{value}}〉$ and $\text{residual achieved}=〈\mathit{\text{value}}〉$.

## 7  Accuracy

The accuracy should be close to machine precision for well conditioned boundary value problems.

## 8  Parallelism and Performance

nag_ode_bvp_ps_lin_solve (d02uec) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_ode_bvp_ps_lin_solve (d02uec) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The number of operations is of the order $n\mathrm{log}\left(n\right)$ and the memory requirements are $\mathit{O}\left(n\right)$; thus the computation remains efficient and practical for very fine discretizations (very large values of $n$). Collocation methods will be faster for small problems, but the method of nag_ode_bvp_ps_lin_solve (d02uec) should be faster for larger discretizations.

## 10  Example

This example solves the third-order problem $4{U}_{xxx}+3{U}_{xx}+2{U}_{x}+U=2\mathrm{sin}x-2\mathrm{cos}x$ on $\left[-\pi /2,\pi /2\right]$ subject to the boundary conditions $U\left[-\pi /2\right]=0$, $3{U}_{xx}\left[-\pi /2\right]+2{U}_{x}\left[-\pi /2\right]+U\left[-\pi /2\right]=2$, and $3{U}_{xx}\left[\pi /2\right]+2{U}_{x}\left[\pi /2\right]+U\left[\pi /2\right]=-2$ using the Chebyshev integration formulation on a Chebyshev Gauss–Lobatto grid of order $16$.

### 10.1  Program Text

Program Text (d02uece.c)

### 10.2  Program Data

Program Data (d02uece.d)

### 10.3  Program Results

Program Results (d02uece.r)