Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_inteq_fredholm2_smooth (d05ab)

## Purpose

nag_inteq_fredholm2_smooth (d05ab) solves any linear nonsingular Fredholm integral equation of the second kind with a smooth kernel.

## Syntax

[f, c, ifail] = d05ab(k, g, lambda, a, b, odorev, ev, n)
[f, c, ifail] = nag_inteq_fredholm2_smooth(k, g, lambda, a, b, odorev, ev, n)

## Description

nag_inteq_fredholm2_smooth (d05ab) uses the method of El–Gendi (1969) to solve an integral equation of the form
 $fx-λ∫abkx,sfsds=gx$
for the function $f\left(x\right)$ in the range $a\le x\le b$.
An approximation to the solution $f\left(x\right)$ is found in the form of an $n$ term Chebyshev series $\underset{i=1}{\overset{n}{{\sum }^{\prime }}}{c}_{i}{T}_{i}\left(x\right)$, where ${}^{\prime }$ indicates that the first term is halved in the sum. The coefficients ${c}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, of this series are determined directly from approximate values ${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, of the function $f\left(x\right)$ at the first $n$ of a set of $m+1$ Chebyshev points
 $xi=12a+b+b-a×cosi-1×π/m, i=1,2,…,m+1.$
The values ${f}_{i}$ are obtained by solving a set of simultaneous linear algebraic equations formed by applying a quadrature formula (equivalent to the scheme of Clenshaw and Curtis (1960)) to the integral equation at each of the above points.
In general $m=n-1$. However, advantage may be taken of any prior knowledge of the symmetry of $f\left(x\right)$. Thus if $f\left(x\right)$ is symmetric (i.e., even) about the mid-point of the range $\left(a,b\right)$, it may be approximated by an even Chebyshev series with $m=2n-1$. Similarly, if $f\left(x\right)$ is anti-symmetric (i.e., odd) about the mid-point of the range of integration, it may be approximated by an odd Chebyshev series with $m=2n$.

## References

Clenshaw C W and Curtis A R (1960) A method for numerical integration on an automatic computer Numer. Math. 2 197–205
El–Gendi S E (1969) Chebyshev solution of differential, integral and integro-differential equations Comput. J. 12 282–287

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{k}$ – function handle or string containing name of m-file
k must compute the value of the kernel $k\left(x,s\right)$ of the integral equation over the square $a\le x\le b$, $a\le s\le b$.
[result] = k(x, s)

Input Parameters

1:     $\mathrm{x}$ – double scalar
2:     $\mathrm{s}$ – double scalar
The values of $x$ and $s$ at which $k\left(x,s\right)$ is to be calculated.

Output Parameters

1:     $\mathrm{result}$ – double scalar
The value of the kernel $k\left(x,s\right)$ evaluated at x and s.
2:     $\mathrm{g}$ – function handle or string containing name of m-file
g must compute the value of the function $g\left(x\right)$ of the integral equation in the interval $a\le x\le b$.
[result] = g(x)

Input Parameters

1:     $\mathrm{x}$ – double scalar
The value of $x$ at which $g\left(x\right)$ is to be calculated.

Output Parameters

1:     $\mathrm{result}$ – double scalar
The value of $g\left(x\right)$ evaluated at x.
3:     $\mathrm{lambda}$ – double scalar
The value of the parameter $\lambda$ of the integral equation.
4:     $\mathrm{a}$ – double scalar
$a$, the lower limit of integration.
5:     $\mathrm{b}$ – double scalar
$b$, the upper limit of integration.
Constraint: ${\mathbf{b}}>{\mathbf{a}}$.
6:     $\mathrm{odorev}$ – logical scalar
Indicates whether it is known that the solution $f\left(x\right)$ is odd or even about the mid-point of the range of integration. If odorev is true then an odd or even solution is sought depending upon the value of ev.
7:     $\mathrm{ev}$ – logical scalar
Is ignored if odorev is false. Otherwise, if ev is true, an even solution is sought, whilst if ev is false, an odd solution is sought.
8:     $\mathrm{n}$int64int32nag_int scalar
The number of terms in the Chebyshev series which approximates the solution $f\left(x\right)$.
Constraint: ${\mathbf{n}}\ge 1$.

None.

### Output Parameters

1:     $\mathrm{f}\left({\mathbf{n}}\right)$ – double array
The approximate values ${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$, of the function $f\left(x\right)$ at the first n of $m+1$ Chebyshev points (see Description), where
 $m=2{\mathbf{n}}-1$ if ${\mathbf{odorev}}=\mathit{true}$ and ${\mathbf{ev}}=\mathit{true}$. $m=2{\mathbf{n}}$ if ${\mathbf{odorev}}=\mathit{true}$ and ${\mathbf{ev}}=\mathit{false}$. $m={\mathbf{n}}-1$ if ${\mathbf{odorev}}=\mathit{false}$.
2:     $\mathrm{c}\left({\mathbf{n}}\right)$ – double array
The coefficients ${c}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$, of the Chebyshev series approximation to $f\left(x\right)$. When odorev is true, this series contains polynomials of even order only or of odd order only, according to ev being true or false respectively.
3:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{a}}\ge {\mathbf{b}}$ or ${\mathbf{n}}<1$.
${\mathbf{ifail}}=2$
A failure has occurred due to proximity to an eigenvalue. In general, if lambda is near an eigenvalue of the integral equation, the corresponding matrix will be nearly singular. In the special case, $m=1$, the matrix reduces to a zero-valued number.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

No explicit error estimate is provided by the function but it is possible to obtain a good indication of the accuracy of the solution either
 (i) by examining the size of the later Chebyshev coefficients ${c}_{i}$, or (ii) by comparing the coefficients ${c}_{i}$ or the function values ${f}_{i}$ for two or more values of n.

The time taken by nag_inteq_fredholm2_smooth (d05ab) depends upon the value of n and upon the complexity of the kernel function $k\left(x,s\right)$.

## Example

This example solves Love's equation:
 $fx+1π ∫-11fs 1+ x-s 2 ds=1 .$
It will solve the slightly more general equation:
 $fx-λ ∫ab kx,sfs ds=1$
where $k\left(x,s\right)=\alpha /\left({\alpha }^{2}+{\left(x-s\right)}^{2}\right)$. The values $\lambda =-1/\pi ,a=-1,b=1,\alpha =1$ are used below.
It is evident from the symmetry of the given equation that $f\left(x\right)$ is an even function. Advantage is taken of this fact both in the application of nag_inteq_fredholm2_smooth (d05ab), to obtain the ${f}_{i}\simeq f\left({x}_{i}\right)$ and the ${c}_{i}$, and in subsequent applications of nag_sum_chebyshev (c06dc) to obtain $f\left(x\right)$ at selected points.
The program runs for ${\mathbf{n}}=5$ and ${\mathbf{n}}=10$.
```function d05ab_example

fprintf('d05ab example results\n\n');

k = @(x, s) 1/(1+(x-s)*(x-s));
g = @(x) 1;
lambda = -0.3183;
a = -1;
b = 1;
odorev = true;
ev     = true;
xval = [0:0.25:1];
ss = int64(2);

for n = 5:5:10;
in = int64(n);
[f, c, ifail] = d05ab(k, g, lambda, a, b, odorev, ev, in);
fprintf('\nResults for N = %2d\n\n', n);
fprintf('Solution and coefficients on first %2d Chebyshev points\n',n);
fprintf('  i           x             f(i)         c(i)\n');
cheb(1:n,1) = cos(pi*(1:n)/(2*n-1));
fprintf('%3d%15.5f%15.5f%15.5e\n', [[1:n]' cheb f c]');

[chebr, ifail] = c06dc(xval, a, b, c, ss);

fprintf('\nSolution on evenly spaced grid\n');
fprintf('     x           f(x)\n');
fprintf('%8.4f%15.5f\n',[xval' chebr]')

end

```
```d05ab example results

Results for N =  5

Solution and coefficients on first  5 Chebyshev points
i           x             f(i)         c(i)
1        0.93969        0.75572    1.41520e+00
2        0.76604        0.74534    4.93840e-02
3        0.50000        0.71729   -1.04758e-03
4        0.17365        0.68319   -2.32817e-04
5       -0.17365        0.66051    2.08903e-05

Solution on evenly spaced grid
x           f(x)
0.0000        0.65742
0.2500        0.66383
0.5000        0.68319
0.7500        0.71489
1.0000        0.75572

Results for N = 10

Solution and coefficients on first 10 Chebyshev points
i           x             f(i)         c(i)
1        0.98636        0.75572    1.41520e+00
2        0.94582        0.75336    4.93840e-02
3        0.87947        0.74639   -1.04751e-03
4        0.78914        0.73525   -2.32749e-04
5        0.67728        0.72081    1.99856e-05
6        0.54695        0.70452    9.86754e-07
7        0.40170        0.68825   -2.37956e-07
8        0.24549        0.67404    1.85810e-09
9        0.08258        0.66361    2.44829e-09
10       -0.08258        0.65812   -1.65268e-10

Solution on evenly spaced grid
x           f(x)
0.0000        0.65742
0.2500        0.66384
0.5000        0.68319
0.7500        0.71489
1.0000        0.75572
```