hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_ode_bvp_fd_nonlin_fixedbc (d02ga)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

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 n differential equations in the interval [a,b]. The system is written in the form:
yi=fix,y1,y2,,yn,  i=1,2,,n (1)
and the derivatives fi are evaluated by fcn. Initially, n boundary values of the variables yi must be specified, some at a and some at b. You must supply estimates of the remaining n 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 fi yj  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:     un2 – double array
ui1 must be set to the known or estimated value of yi at a and ui2 must be set to the known or estimated value of yi at b, for i=1,2,,n.
2:     vn2 – double array
vij must be set to 0.0 if uij is a known value and to 1.0 if uij is an estimated value, for i=1,2,,n and j=1,2.
Constraint: precisely n of the vij must be set to 0.0, i.e., precisely n of the uij must be known values, and these must not be all at a or all at b.
3:     a – double scalar
a, the left-hand boundary point.
4:     b – double scalar
b, the right-hand boundary point.
Constraint: b>a.
5:     tol – double scalar
A positive absolute error tolerance. If
a=x1<x2<<xnp=b  
is the final mesh, zjxi is the jth component of the approximate solution at xi, and yjx is the jth component of the true solution of equation (1) (see Description) and the boundary conditions, then, except in extreme cases, it is expected that
zjxi-yjxitol,  i=1,2,,np​ and ​j=1,2,,n. (2)
Constraint: tol>0.0.
6:     fcn – function handle or string containing name of m-file
fcn must evaluate the functions fi (i.e., the derivatives yi), for i=1,2,,n, at a general point x.
[f] = fcn(x, y)

Input Parameters

1:     x – double scalar
x, the value of the argument.
2:     y: – double array
yi, for i=1,2,,n, the value of the argument.

Output Parameters

1:     f: – double array
The values of fi, for i=1,2,,n.
7:     xmnp – double array
If np4 (see np), the first np elements must define an initial mesh. Otherwise the elements of x need not be set.
Constraint:
a=x1<x2<<xnp=b,   np4.(3)
8:     np int64int32nag_int scalar
Determines whether a default or user-supplied mesh is used.
np=0
A default value of 4 for np and a corresponding equispaced mesh x1,x2,,xnp are used.
np4
You must define an initial mesh using the array x as described.
Constraint: np=0 or 4npmnp.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the first dimension of the arrays u, v. (An error is raised if these dimensions are not equal.)
n, the number of equations.
Constraint: n2.
2:     mnp int64int32nag_int scalar
Default: the dimension of the array x.
The maximum permitted number of mesh points.
Constraint: mnp32.

Output Parameters

1:     xmnp – double array
x1,x2,,xnp define the final mesh (with the returned value of np) satisfying the relation (3).
2:     ynmnp – double array
The approximate solution zjxi satisfying (2), on the final mesh, that is
yji=zjxi,  i=1,2,,np​ and ​j=1,2,,n,  
where np is the number of points in the final mesh.
The remaining columns of y are not used.
3:     np int64int32nag_int scalar
The number of points in the final (returned) mesh.
4:     ifail int64int32nag_int scalar
ifail=0 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.

   ifail=1
One or more of the arguments n, tol, np, mnp, lw or liw has been incorrectly set, or ba, or the condition (3) on x is not satisfied, or the number of known boundary values (specified by v) is not n.
   ifail=2
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  ifail=3
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  ifail=4
A finer mesh is required for the accuracy requested; that is mnp is not large enough.
   ifail=5
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.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
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
y=-yy-β1-y2  
with boundary conditions
y0=y0= 0,   y10=1  
for β=0.0 and β=0.2 to an accuracy specified by tol=1.0e−3. We solve first the simpler problem with β=0.0 using an equispaced mesh of 26 points and then we solve the problem with β=0.2 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).
function d02ga_example


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

% For communication with fcn & display_plot.
global beta;

% Initialize variables and arrays.
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

  % Plot results.
  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)
  % For communication with the main routine.
  global beta;

  % Evaluate the derivatives.
  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)
  % For communication with the main routine.
  global beta;
  % Plot the three curves.
  plot(x, y(1,:), '-+', ...
       x, y(2,:), '--x', ...
       x, y(3,:), ':*');
  % Add title.
  title({['Two-point Boundary-value Problem using'],...
         ['Deferred Correction Technique (\beta = ',num2str(beta),')']});
  % Label the axes.
  xlabel('x');
  ylabel('Solution');
  % Add legend.
  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
 
d02ga_fig1.png
d02ga_fig2.png

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015