YAMP.Numerics.SplineInterpolation.ComputeValue C# (CSharp) Method

ComputeValue() public method

Computes a specific interpolated value f(x).
public ComputeValue ( double x ) : double
x double The value where to interpolate.
return double
        public override double ComputeValue(double x)
        {
            MatrixValue samples = Samples;

            if (a.Length > 1)
            {
                int gap = 1;
                double previous = 0.0;

                for (int i = 1; i < a.Length; i++)
                {
                    if (samples[i, 1].Re < x && (i == 1 || samples[i, 1].Re > previous))
                    {
                        previous = samples[i, 1].Re;
                        gap = i;
                    }
                }

                double x1 = x - previous;
                double x2 = h[gap] - x1;
                return ((-a[gap - 1] / 6 * (x2 + h[gap]) * x1 + samples[gap, 2].Re) * x2 + (-a[gap] / 6 * (x1 + h[gap]) * x2 + samples[gap + 1, 2].Re) * x1) / h[gap];
            }

            return 0;
        }

Usage Example

Exemplo n.º 1
0
 public MatrixValue Function(MatrixValue original, ScalarValue x)
 {
     var spline = new SplineInterpolation(original);
     var M = new MatrixValue(1, 2);
     M[1, 1].Re = x.Re;
     M[1, 2].Re = spline.ComputeValue(x.Re);
     return M;
 }