Beispiel #1
0
        /// <summary>
        /// Nodes between two points, compressed at both ends
        /// </summary>
        /// <param name="l">lower limit.</param>
        /// <param name="r">upper limit.</param>
        /// <param name="a">scaling between linear ans sinus-mapping</param>
        /// <param name="n">number of nodes</param>
        /// <returns></returns>
        public static double[] SinLinSpacing(double l, double r, double a, int n)
        {
            if (a < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (a > 1)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (l >= r)
            {
                throw new ArgumentOutOfRangeException();
            }

            double[] linnodes  = GenericBlas.Linspace(-Math.PI * 0.5, Math.PI * 0.5, n);
            double[] linnodes2 = GenericBlas.Linspace(-1, 1, n);
            double[] nodes     = new double[n];

            for (int i = 0; i < n; i++)
            {
                //nodes[i] = linnodes2[i] * (1 - a) + (1.0 - Math.Sin(linnodes[i])) * a;
                nodes[i] = linnodes2[i] * (1 - a) + Math.Sin(linnodes[i]) * a;
            }

            for (int i = 0; i < n; i++)
            {
                nodes[i] = nodes[i] * (r - l) * 0.5 + (r + l) * 0.5;
                //Debug.Assert(nodes[i] >= l);
                //Debug.Assert(nodes[i] <= r);
            }
            return(nodes);
        }
Beispiel #2
0
        /// <summary>
        /// <paramref name="a"/> = <paramref name="alpha"/>*<paramref name="B"/>
        /// </summary>
        static public void SetV <T, V>(this T a, V B, double alpha = 1.0)
            where T : IList <double>
            where V : IList <double> //
        {
            int N = a.Count;

            if (B.Count != N)
            {
                throw new ArgumentException("element count must be equal");
            }
            if (object.ReferenceEquals(a, B))
            {
                // while formally there is no problem that this should work, it seems much more likely
                // that it's a bug, i.e. the user called it un-intentionally.
                throw new ArgumentException("Illegal use: reference-equality of input vectors -- this might be a mis-use instead of intention.");
            }
            a.ClearEntries();
            GenericBlas.daxpy(N, alpha, B, 1, a, 1);
        }
Beispiel #3
0
 /// <summary>
 /// scales some vector <paramref name="a"/> by scalar <paramref name="alpha"/>.
 /// </summary>
 static public void ScaleV <T>(this T a, double alpha) where T : IList <double>
 {
     GenericBlas.dscal(a.Count, alpha, a, 1);
 }