Interpolation

Functions enable interpolation and extrapolation for arguments. For example in an function F defined as

            IVariable x = new Variable<double>("x");
            IVariable y = new Variable<double>("y");

            IFunction f = new Function {Arguments = {x}, Components = {y}};
            
            f[0.0d] = 0.0d;
            f[2.0d] = 2.0d;

We can an interpolated value like this

            Assert.AreEqual(1,f.Evaluate<double>(new VariableValueFilter<double>(x,new[]{1.0d})));

In this sample the default interpolation method linear is used. We can also specify another interpolationtype like Constant

            x.InterpolationType = ApproximationType.Constant;
            Assert.AreEqual(0,f.Evaluate<double>(new VariableValueFilter<double>(x,new[]{1.0d})));

Or we can disable interpolation and get an exception

            x.InterpolationType = ApproximationType.Constant;
            f.Evaluate<double>(new VariableValueFilter<double>(x,new[]{1.0d})));//expection here

Extrapolation

Extrapolation works just like interpolation. Except we use the variable extrapolationtype to define behaviour. Extrapolation is used for evaluating functions outside of the range of the arguments.

            IVariable x = new Variable<double>("x");
            IVariable y = new Variable<double>("y");

            IFunction f = new Function {Arguments = {x}, Components = {y}};

            x.ExtraPolationType = ApproximationType.Linear;
            f[0.0d] = 0.0d;
            f[2.0d] = 2.0d;
            //get value using extrapolation.
            Assert.AreEqual(4.0d,f.Evaluate<double>(new VariableValueFilter<double>(x,new[]{4.0d})));

Approximation types

Linear : value is determined by a linear approximation using nearest defined values.
Constant: value is determined by the previously defined value. Also known as PieceWiseConstant
None : disabled.

Issues / TODO

Approximation per component argument pair
Now approximation is given per argument. But in multiplecomponent functions is might be reasonable to have different approximation methods per component for an argument. Then a component should have a list of approximationtypes for it's arguments or something.

Syntax of evaluate
The evaluate syntax is not user-friendly and should resemble the x1 syntax more. It might even be possible to use approximation for x1 (the indexer) but this breaks a lot of code and we need another method to get the not approximated values.

  • No labels