PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_ode_bvp_fd_nonlin_fixedbc (d02ga)
Purpose
nag_ode_bvp_fd_nonlin_fixedbc (d02ga) solves a two-point boundary value problem with assigned boundary values for a system of ordinary differential equations, using a deferred correction technique and a Newton iteration.
Syntax
[
x,
y,
np,
ifail] = d02ga(
u,
v,
a,
b,
tol,
fcn,
x,
np, 'n',
n, 'mnp',
mnp)
[
x,
y,
np,
ifail] = nag_ode_bvp_fd_nonlin_fixedbc(
u,
v,
a,
b,
tol,
fcn,
x,
np, 'n',
n, 'mnp',
mnp)
Description
nag_ode_bvp_fd_nonlin_fixedbc (d02ga) solves a two-point boundary value problem for a system of
differential equations in the interval [
]. The system is written in the form:
and the derivatives
are evaluated by
fcn. Initially,
boundary values of the variables
must be specified, some at
and some at
. You must supply estimates of the remaining
boundary values and all the boundary values are used in constructing an initial approximation to the solution. This approximate solution is corrected by a finite difference technique with deferred correction allied with a Newton iteration to solve the finite difference equations. The technique used is described fully in
Pereyra (1979). The Newton iteration requires a Jacobian matrix
and this is calculated by numerical differentiation using an algorithm described in
Curtis et al. (1974).
You supply an absolute error tolerance and may also supply an initial mesh for the construction of the finite difference equations (alternatively a default mesh is used). The algorithm constructs a solution on a mesh defined by adding points to the initial mesh. This solution is chosen so that the error is everywhere less than your tolerance and so that the error is approximately equidistributed on the final mesh. The solution is returned on this final mesh.
If the solution is required at a few specific points then these should be included in the initial mesh. If on the other hand the solution is required at several specific points then you should use the interpolation functions provided in
Chapter E01 if these points do not themselves form a convenient mesh.
References
Curtis A R, Powell M J D and Reid J K (1974) On the estimation of sparse Jacobian matrices J. Inst. Maths. Applics. 13 117–119
Pereyra V (1979) PASVA3: An adaptive finite-difference Fortran program for first order nonlinear, ordinary boundary problems Codes for Boundary Value Problems in Ordinary Differential Equations. Lecture Notes in Computer Science (eds B Childs, M Scott, J W Daniel, E Denman and P Nelson) 76 Springer–Verlag
Parameters
Compulsory Input Parameters
- 1:
– double array
-
must be set to the known or estimated value of at and must be set to the known or estimated value of at , for .
- 2:
– double array
-
must be set to if is a known value and to if is an estimated value, for and .
Constraint:
precisely of the must be set to , i.e., precisely of the must be known values, and these must not be all at or all at .
- 3:
– double scalar
-
, the left-hand boundary point.
- 4:
– double scalar
-
, the right-hand boundary point.
Constraint:
.
- 5:
– double scalar
-
A positive absolute error tolerance. If
is the final mesh,
is the
th component of the approximate solution at
, and
is the
th component of the true solution of equation
(1) (see
Description) and the boundary conditions, then, except in extreme cases, it is expected that
Constraint:
.
- 6:
– function handle or string containing name of m-file
-
fcn must evaluate the functions
(i.e., the derivatives
), for
, at a general point
.
[f] = fcn(x, y)
Input Parameters
- 1:
– double scalar
-
, the value of the argument.
- 2:
– double array
-
, for , the value of the argument.
Output Parameters
- 1:
– double array
-
The values of
, for .
- 7:
– double array
-
If
(see
np), the first
np elements must define an initial mesh. Otherwise the elements of
x need not be set.
- 8:
– int64int32nag_int scalar
-
Determines whether a default or user-supplied mesh is used.
- A default value of for np and a corresponding equispaced mesh are used.
- You must define an initial mesh using the array x as described.
Constraint:
or .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the first dimension of the arrays
u,
v. (An error is raised if these dimensions are not equal.)
, the number of equations.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
x.
The maximum permitted number of mesh points.
Constraint:
.
Output Parameters
- 1:
– double array
-
define the final mesh (with the returned value of
np) satisfying the relation
(3).
- 2:
– double array
-
The approximate solution
satisfying
(2), on the final mesh, that is
where
np is the number of points in the final mesh.
The remaining columns of
y are not used.
- 3:
– int64int32nag_int scalar
-
The number of points in the final (returned) mesh.
- 4:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
One or more of the arguments
n,
tol,
np,
mnp,
lw or
liw has been incorrectly set, or
, or the condition
(3) on
x is not satisfied, or the number of known boundary values (specified by
v) is not
n.
-
-
The Newton iteration has failed to converge. This could be due to there being too few points in the initial mesh or to the initial approximate solution being too inaccurate. If this latter reason is suspected you should use
nag_ode_bvp_fd_nonlin_gen (d02ra) instead. If the warning ‘Jacobian matrix is singular’ is printed this could be due to specifying zero estimated boundary values and these should be varied. This warning could also be printed in the unlikely event of the Jacobian matrix being calculated inaccurately. If you cannot make changes to prevent the warning then
nag_ode_bvp_fd_nonlin_gen (d02ra) should be used.
- W
-
The Newton iteration has reached round-off level. It could be, however, that the answer returned is satisfactory. This error might occur if too much accuracy is requested.
- W
-
A finer mesh is required for the accuracy requested; that is
mnp is not large enough.
-
-
A serious error has occurred in a call to nag_ode_bvp_fd_nonlin_fixedbc (d02ga). Check all array subscripts and function argument lists in calls to nag_ode_bvp_fd_nonlin_fixedbc (d02ga). Seek expert help.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The solution returned by the function will be accurate to your tolerance as defined by the relation
(2) except in extreme circumstances. If too many points are specified in the initial mesh, the solution may be more accurate than requested and the error may not be approximately equidistributed.
Further Comments
The time taken by nag_ode_bvp_fd_nonlin_fixedbc (d02ga) depends on the difficulty of the problem, the number of mesh points (and meshes) used, the number of Newton iterations and the number of deferred corrections.
You are strongly recommended to set
ifail to obtain self-explanatory error messages, and also monitoring information about the course of the computation. You may select the channel numbers on which this output is to appear by calls of
nag_file_set_unit_error (x04aa) (for error messages) or
nag_file_set_unit_advisory (x04ab) (for monitoring information) – see
Example for an example. Otherwise the default channel numbers will be used.
A common cause of convergence problems in the Newton iteration is that you have specified too few points in the initial mesh. Although the function adds points to the mesh to improve accuracy it is unable to do so until the solution on the initial mesh has been calculated in the Newton iteration.
If you specify zero known and estimated boundary values, the function constructs a zero initial approximation and in many cases the Jacobian is singular when evaluated for this approximation, leading to the breakdown of the Newton iteration.
You may be unable to provide a sufficiently good choice of initial mesh and estimated boundary values, and hence the Newton iteration may never converge. In this case the continuation facility provided in
nag_ode_bvp_fd_nonlin_gen (d02ra) is recommended.
In the case where you wish to solve a sequence of similar problems, the final mesh from solving one case is strongly recommended as the initial mesh for the next.
Example
This example solves the differential equation
with boundary conditions
for
and
to an accuracy specified by
. We solve first the simpler problem with
using an equispaced mesh of
points and then we solve the problem with
using the final mesh from the first problem.
Note the call to
nag_file_set_unit_advisory (x04ab) prior to the call to
nag_ode_bvp_fd_nonlin_fixedbc (d02ga).
Open in the MATLAB editor:
d02ga_example
function d02ga_example
fprintf('d02ga example results\n\n');
global beta;
u = [0, 10; 0, 1; 0, 0];
v = [0, 1; 0, 0; 1, 1];
a = 0;
b = 10;
tol = 0.001;
x = zeros(40, 1);
np = int64(26);
beta = double(0);
n = 3;
for i = 2:np-1
x(i) = (double(np-i)*a+double(i-1)*b)/double(np-1);
end
x(np) = b;
for k = 1:2
[xOut, y, npOut, ifail] = ...
d02ga(...
u, v, a, b, tol, @fcn, x, np);
fprintf('Problem with beta = %1.2f \n\n',beta);
fprintf('Solution on final mesh of %1.0f points\n\n',npOut);
disp(' x y_1 y_2 y_3');
for i = 1:npOut;
fprintf('%6.3f %8.5f %8.5f %8.5f\n', x(i),y(1:3,i));
end
xplot = x(1:npOut);
yplot = y(:,1:npOut);
if k == 1
fig1 = figure;
display_plot(xplot, yplot);
else
fig2 = figure;
display_plot(xplot, yplot);
end
disp(' ');
beta = double(beta + 0.2);
end
function f = fcn(x,y)
global beta;
f = zeros(3,1);
f(1) = y(2);
f(2) = y(3);
f(3) = -y(1)*y(3)- beta*(1.0-y(2)*y(2));
function display_plot(x, y)
global beta;
plot(x, y(1,:), '-+', ...
x, y(2,:), '--x', ...
x, y(3,:), ':*');
title({['Two-point Boundary-value Problem using'],...
['Deferred Correction Technique (\beta = ',num2str(beta),')']});
xlabel('x');
ylabel('Solution');
legend('y','y''','y''''','Location','Best');
d02ga example results
Problem with beta = 0.00
Solution on final mesh of 26 points
x y_1 y_2 y_3
0.000 0.00000 0.00000 0.46948
0.400 0.03754 0.18762 0.46725
0.800 0.14970 0.37191 0.45109
1.200 0.33363 0.54504 0.41042
1.600 0.58277 0.69635 0.34245
2.000 0.88639 0.81635 0.25584
2.400 1.23094 0.90088 0.16781
2.800 1.60263 0.95288 0.09525
3.200 1.98997 0.98045 0.04636
3.600 2.38505 0.99296 0.01928
4.000 2.78340 0.99780 0.00686
4.400 3.18292 0.99940 0.00210
4.800 3.58279 0.99986 0.00055
5.200 3.98276 0.99997 0.00012
5.600 4.38276 1.00000 0.00002
6.000 4.78276 1.00000 0.00000
6.400 5.18276 1.00000 0.00000
6.800 5.58276 1.00000 0.00000
7.200 5.98276 1.00000 -0.00000
7.600 6.38276 1.00000 0.00000
8.000 6.78276 1.00000 -0.00000
8.400 7.18276 1.00000 0.00000
8.800 7.58276 1.00000 -0.00000
9.200 7.98276 1.00000 0.00000
9.600 8.38276 1.00000 -0.00000
10.000 8.78276 1.00000 -0.00000
Problem with beta = 0.20
Solution on final mesh of 26 points
x y_1 y_2 y_3
0.000 0.00000 0.00000 0.68654
0.400 0.05279 0.25843 0.60395
0.800 0.20203 0.48144 0.50912
1.200 0.43245 0.66359 0.40014
1.600 0.72676 0.80075 0.28602
2.000 1.06701 0.89385 0.18212
2.400 1.43680 0.94979 0.10167
2.800 1.82330 0.97911 0.04923
3.200 2.21802 0.99240 0.02056
3.600 2.61623 0.99759 0.00740
4.000 3.01569 0.99933 0.00230
4.400 3.41555 0.99984 0.00062
4.800 3.81552 0.99997 0.00014
5.200 4.21551 0.99999 0.00003
5.600 4.61551 1.00000 0.00000
6.000 5.01551 1.00000 0.00000
6.400 5.41551 1.00000 -0.00000
6.800 5.81551 1.00000 -0.00000
7.200 6.21551 1.00000 -0.00000
7.600 6.61551 1.00000 -0.00000
8.000 7.01551 1.00000 -0.00000
8.400 7.41551 1.00000 -0.00000
8.800 7.81551 1.00000 -0.00000
9.200 8.21551 1.00000 -0.00000
9.600 8.61551 1.00000 -0.00000
10.000 9.01551 1.00000 -0.00000
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015