\documentstyle[12pt]{article}
\textwidth 16cm
\textheight 23cm
\topmargin 0cm
\evensidemargin 0cm
\oddsidemargin 0cm
\parindent=0pt
\parskip=10pt
\begin{document}


\begin{center}
\Large \bf
Numerieke methoden in de natuurwetenschappen\\
\large 
\end{center}
\vspace{0.4cm}
\noindent 
{\bf Ex.~3b: Cubic spline interpolation. Numerical solution by use of the NAG 
library}\\

Suppose we have a set of datapoints 
\{($x_0,f(x_0)$),($x_1,f(x_1)$), ($x_n,f(x_n)$)\} can be interpolated by 
use of a piecewise polynomial approximation.  The most common method is the 
cubic spline interpolation. The method is described in Sect. 3.4 of the book 
Numerical analysis by Burden and Faires. Given $n$ points, 
$n$ cubic polinomials $S_j$ ($j$=0,1,.. $n$-1)of the form
$$ S_j=a_j+b_j(x-x_j)+c_j(x-x_j)^2+d_j(x-x_j)^3$$
are constructed by imposing the conditions b-f given in the book. As 
shown there, the problem of determining the coefficients of the polynomials 
$S_j$ is reduced to finding the solutions of the system of linear equations 
of the form A{\bf y}={\bf b} given by eq. 3.22. 

Consider now the exercise 5 of the set 3.4 of the same book. 
The purpose is to construct a free cubic spline for 
the function cos($\pi$ x) by using the numerical values at 5 points, 
x=0., 0.25,0.5,0.75, 1. 
Write a program to construct the matrix A and the vector {\bf b}. Solve 
the problem by use of a subroutine chosen within the NAG library and compare 
the cubic spline to the original function cos(x). 

The NAG library is a collection of  ready-to-use subroutines which can be 
called from a f77, f90 or C program. It is useful to learn using them. 
The first step is to identify the appropriate 
subroutine, the second to understand which is the required input and 
where the output is given. A list of the avalaible subroutines can be found by 
invoking nagdtext or by looking at 
the manuals on paper which can be found in the computer room of mathematics 
on the second floor.  A description of how to use them can be found at:

http://www.sci.kun.nl/cncz/software/local/html/nag.html.

In short, you have to give the path by typing:

setenv LD\_LIBRARY\_PATH /usr/lib:/usr/ccs/lib:/usr/local/lib

and compile with the options:


f90 myprog.f90~~  -lnag -lF77

or (hopefully, let me know if it works)

CC  myprog.c 
%-L/opt/SUNWspro/lib -R/opt/SUNWspro/lib 
-lnag -lF77 -lM77 -lsunmath -lm -lc


The -lF77 option is needed because the NAG library is written in F77.

\end{document}

