Example #1
0
        public static DenseMatrix[] Assign2D(this DenseMatrix[] m2d, Func <int, int, float> vFuncX, Func <int, int, float> vFuncY)
        {
            if (m2d == null)
            {
                m2d = MatrixFactory.New2D(vFuncX, vFuncY);
            }
            else
            {
                if (m2d[Direction.X] == null)
                {
                    m2d[Direction.X] = MatrixFactory.New(vFuncX);
                }
                else
                {
                    m2d[Direction.X].Assign(vFuncX);
                }

                if (m2d[Direction.Y] == null)
                {
                    m2d[Direction.Y] = MatrixFactory.New(vFuncY);
                }
                else
                {
                    m2d[Direction.Y].Assign(vFuncY);
                }
            }

            return(m2d);
        }
Example #2
0
        //-----------------------------------------------------------------

        public static DenseMatrix Assign(this DenseMatrix m, Func <int, int, float> vFunc)
        {
            if (m == null)
            {
                m = MatrixFactory.New(vFunc);
            }
            else
            {
                for (int r = 0; r < m.RowCount; r++)
                {
                    for (int c = 0; c < m.ColumnCount; c++)
                    {
                        if (vFunc != null)
                        {
                            m[r, c] = vFunc(r, c);
                        }
                        else
                        {
                            m[r, c] = 0;
                        }
                    }
                }
            }

            return(m);
        }
Example #3
0
        public static DenseMatrix Rescale(this DenseMatrix V, float[] finalScale, float[] initialScale = null)
        {
            float max = 0;
            float min = 0;

            if (initialScale == null)
            {
                min = V.Min();
                max = V.Max();
            }
            else
            {
                min = initialScale[0];
                max = initialScale[1];
            }

            return(MatrixFactory.New((r, c) =>
            {
                if (min != max)
                {
                    var m = (V[r, c] - min) / (max - min);
                    return finalScale[0] + m * (finalScale[1] - finalScale[0]);
                }

                return min;
            }));
        }
Example #4
0
 public static DenseMatrix[] New2D(Func <int, int, float> vFuncX, Func <int, int, float> vFuncY)
 {
     return(new DenseMatrix[]
     {
         MatrixFactory.New(vFuncX),
         MatrixFactory.New(vFuncY),
     });
 }
Example #5
0
        // TODO: move to dedicated atmosheric calculus class
        public static DenseMatrix EnsureScale(this DenseMatrix V, float[] range)
        {
            if (range == null)
            {
                range = V.IdentifyPressureRange();
            }

            float min = range[0];
            float max = range[1];

            var V2 = MatrixFactory.New((r, c) =>
            {
                return(Math.Min(max, Math.Max(min, V[r, c])));
            }).EQ();

            return(V2);
        }