using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using NagCFunctionsAPI; 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 m = x.Length; int n = 2 * m - 1; double[] d = new double[m]; double[] px = new double[n]; double[] pf = new double[n]; NagError fail = new NagError(); try { NagFunctions.e01bec(m, 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,...,m-1, are not in strictly increasing order."); default: break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } //fill px with values to be evaluated for (int i = 0; i < m; i++) { px[2 * i] = x[i]; if (i > 0) px[2 * i - 1] = 0.5 * (x[i - 1] + x[i]); } if (fail.code == 0) { try { NagFunctions.e01bfc(m, x, y, d, n, 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,...,m-1, are not in strictly increasing order."); case 246: throw new Exception("At least one of the points px[i], for i= 0,1,...,n-1, lies outside the interval [x[0],x[m-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(ex.Message); } Console.WriteLine("Abscissa Interpolated Values"); for (int i = 0; i < n; i++) { Console.WriteLine("{0} \t {1, 10:f4}", px[i], pf[i]); } } } } }