using System; using System.Windows.Forms; namespace Science.Mathematics.Calculus { /// /// Interpolation with three different ways. /// public class Interpolation1D { private int n; private double[] xa; private double[] ya; public Interpolation1D() { } public double[] MapFrom { set { xa = value; n = xa.Length; } } public double[] MapTo { set { ya = value; n = ya.Length; } } public Interpolation1D(double[] mapFrom, double[] mapTo) { n = mapFrom.Length; xa = mapFrom; ya = mapTo; } public void ComputeForPolynomial() { Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Polint obj = new Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Polint(); if (Science.Net.Check()) { obj.polint(xa, ya, n, at); dy = obj.Error; y = obj.Y; } else { try { throw new Exception(); } catch (Exception) { MessageBox.Show("Please support our authors.", "Invalid user", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } public void ComputeForRational() { Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Ratint obj = new Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Ratint(); if (Science.Net.Check()) { obj.ratint(xa, ya, n, at); dy = obj.Dy; y = obj.Y; } else { try { throw new Exception(); } catch (Exception) { MessageBox.Show("Please support our authors.", "Invalid user", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } public void ComputeForSpline() { double[] y2 = new Double[n]; Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Spline obj = new Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Spline(); if (Science.Net.Check()) { obj.spline(xa, ya, n, start, end, y2); } else { try { throw new Exception(); } catch (Exception) { MessageBox.Show("Please support our authors.", "Invalid user", MessageBoxButtons.OK, MessageBoxIcon.Error); } } Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Splint obj1 = new Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Splint(); obj1.splint(xa, ya ,y2, n, at); } public void ComputePolynomialCoefficients() { coef = new double[n]; Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Polcoe obj = new Science.Mathematics.NumericalRecipes.InterpolationAndExtrapolation.Polcoe(); if (Science.Net.Check()) { obj.polcoe(xa, ya, n - 1, coef); } else { try { throw new Exception(); } catch (Exception) { MessageBox.Show("Please support our authors.", "Invalid user", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private double at = 0.0, y = 0.0, dy = 0.0; private double start = 0.0, end = 0.0; private double[] coef; public double At // input { set{at=value;} } public double DerivativeOfSplineAtStart // input { set { start = value; } } public double DerivativeOfSplineAtEnd // input { set { end = value; } } public double Result // output { get{return y;} } public double Error // output { get{return dy;} } public double[] PolynomialCoefficients // output { get{return coef;} } } }