using System; using System.Text; using System.Runtime.InteropServices; using NagLibrary; namespace E01BEC { class Program { static void Main(string[] args) { double[] x = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0 }; double[] y = { 0, 0.841470985, 0.909297427, 0.141120008, -0.756802495, -0.958924275, -0.279415498, 0.656986599, 0.989358247, 0.412118485, -0.544021111, -0.999990207, -0.536572918, 0.420167037 }; int n = x.Length; int m = 2 * n - 1; double[] d = new double[n]; double[] px = new double[m]; double[] pf = new double[m]; nag_declarations.NagError fail = new nag_declarations.NagError(); try { /* nag_monotonic_interpolant (e01bec). * Interpolating function, monotonicity-preserving, * piecewise cubic Hermite, one variable */ nag_declarations.e01bec(n, x, y, d, ref fail); switch (fail.code) { case 11: throw new Exception("On entry, n < 2."); case 245: throw new Exception("The values of x[r], for r = 0,1,...,n-1, are not in strictly increasing order."); default: break; } } catch (Exception ex) { Console.WriteLine("Error from nag_monotonic_interpolant (e01bec):"); Console.WriteLine(ex.Message); } if (fail.code == 0) { //fill px with values to be evaluated for (int i = 0; i < n; i++) { px[2 * i] = x[i]; if (i > 0) px[2 * i - 1] = 0.5 * (x[i - 1] + x[i]); } try { /* nag_monotonic_evaluate (e01bfc). * Evaluation of interpolant computed by * nag_monotonic_interpolant (e01bec), function only */ nag_declarations.e01bfc(n, x, y, d, m, px, pf, ref fail); switch (fail.code) { case 11: throw new Exception("On entry, n < 2 or m < 1."); case 245: throw new Exception("The values of x[r], for r = 0,1,...,n-1, are not in strictly increasing order."); case 246: throw new Exception("At least one of the points px[i], for i= 0,1,...,m-1, lies outside the interval [x[0],x[n-1]], and the extrapolation was performed at all such points. Values computed at such points may be very unreliable."); default: break; } } catch (Exception ex) { Console.WriteLine("Error from nag_monotonic_evaluate (e01bfc):"); Console.WriteLine(ex.Message); } if (fail.code == 0) { Console.WriteLine("Abscissa Interpolated Values"); for (int i = 0; i < m; i++) { Console.WriteLine("{0} \t {1, 10:f4}", px[i], pf[i]); } } } } } }