Ejemplo n.º 1
0
        public static IFloatMatrix AU(IFloatMatrix A, IROFloatVector u, int r1, int r2, int c1, int c2, IFloatVector v)
        {
            if (r2 < r1 || c2 < c1)
            {
                return(A);
            }

            if (c2 - c1 + 1 > u.Length)
            {
                throw new ArgumentException("Householder vector too short.", "u");
            }

            if (r2 - r1 + 1 > v.Length)
            {
                throw new ArgumentException("Work vector too short.", "v");
            }

            for (int i = r1; i <= r2; i++)
            {
                v[i - r1] = 0.0f;
                for (int j = c1; j <= c2; j++)
                {
                    v[i - r1] = v[i - r1] + A[i, j] * u[j - c1];
                }
            }
            for (int i = r1; i <= r2; i++)
            {
                for (int j = c1; j <= c2; j++)
                {
                    A[i, j] = A[i, j] - v[i - r1] * u[j - c1];
                }
            }
            return(A);
        }
Ejemplo n.º 2
0
 public static IFloatMatrix AU(IFloatMatrix A, IROFloatVector u, int r1, int r2, int c1, int c2)
 {
     if (r2 < r1)
     {
         return(A);
     }
     return(AU(A, u, r1, r2, c1, c2, new FloatVector(r2 - r1 + 1)));
 }
Ejemplo n.º 3
0
 public static IROFloatMatrix UA(IROFloatVector u, IFloatMatrix A, int r1, int r2, int c1, int c2)
 {
     if (c1 > c2)
     {
         return(A);
     }
     return(UA(u, A, r1, r2, c1, c2, new FloatVector(c2 - c1 + 1)));
 }
Ejemplo n.º 4
0
        public static FloatVector GenerateColumn(IFloatMatrix A, int r1, int r2, int c)
        {
            int         ru = r2 - r1 + 1;
            FloatVector u  = new FloatVector(r2 - r1 + 1);

            for (int i = r1; i <= r2; i++)
            {
                u[i - r1] = A[i, c];
                A[i, c]   = 0.0f;
            }

            float norm = u.GetNorm();

            if (r1 == r2 || norm == 0)
            {
                A[r1, c] = -u[0];
                u[0]     = (float)System.Math.Sqrt(2);
                return(u);
            }

            float scale = 1.0f / norm;

            if (u[0] < 0.0f)
            {
                scale *= -1.0f;
            }

            A[r1, c] = -1.0f / scale;

            for (int i = 0; i < ru; i++)
            {
                u[i] = u[i] * scale;
            }

            u[0] = u[0] + 1.0f;
            float s = (float)System.Math.Sqrt(1 / u[0]);

            for (int i = 0; i < ru; i++)
            {
                u[i] = s * u[i];
            }
            return(u);
        }
Ejemplo n.º 5
0
        public static FloatVector GenerateRow(IFloatMatrix A, int r, int c1, int c2)
        {
            int         cu = c2 - c1 + 1;
            FloatVector u  = new FloatVector(cu);

            for (int j = c1; j <= c2; j++)
            {
                u[j - c1] = A[r, j];
                A[r, j]   = 0.0f;
            }

            float norm = u.GetNorm();

            if (c1 == c2 || norm == 0)
            {
                A[r, c1] = -u[0];
                u[0]     = (float)System.Math.Sqrt(2);
                return(u);
            }

            float scale = 1.0f / norm;

            if (u[0] < 0.0f)
            {
                scale *= -1.0f;
            }

            A[r, c1] = -1.0f / scale;

            for (int j = 0; j < cu; j++)
            {
                u[j] *= scale;
            }

            u[0] += 1.0f;
            float s = (float)System.Math.Sqrt(1 / u[0]);

            for (int j = 0; j < cu; j++)
            {
                u[j] *= s;
            }
            return(u);
        }
Ejemplo n.º 6
0
		public static IFloatMatrix AU(IFloatMatrix A, IROFloatVector u, int r1, int r2, int c1, int c2)
		{
			if (r2 < r1)
			{
				return A;
			}
			return AU(A, u, r1, r2, c1, c2, new FloatVector(r2 - r1 + 1));
		}
Ejemplo n.º 7
0
		public static IFloatMatrix AU(IFloatMatrix A, IROFloatVector u, int r1, int r2, int c1, int c2, IFloatVector v)
		{
			if (r2 < r1 || c2 < c1)
			{
				return A;
			}

			if (c2 - c1 + 1 > u.Length)
			{
				throw new ArgumentException("Householder vector too short.", "u");
			}

			if (r2 - r1 + 1 > v.Length)
			{
				throw new ArgumentException("Work vector too short.", "v");
			}

			for (int i = r1; i <= r2; i++)
			{
				v[i - r1] = 0.0f;
				for (int j = c1; j <= c2; j++)
				{
					v[i - r1] = v[i - r1] + A[i, j] * u[j - c1];
				}
			}
			for (int i = r1; i <= r2; i++)
			{
				for (int j = c1; j <= c2; j++)
				{
					A[i, j] = A[i, j] - v[i - r1] * u[j - c1];
				}
			}
			return A;
		}
Ejemplo n.º 8
0
		public static IROFloatMatrix UA(IROFloatVector u, IFloatMatrix A, int r1, int r2, int c1, int c2)
		{
			if (c1 > c2)
			{
				return A;
			}
			return UA(u, A, r1, r2, c1, c2, new FloatVector(c2 - c1 + 1));
		}
Ejemplo n.º 9
0
		public static FloatVector GenerateRow(IFloatMatrix A, int r, int c1, int c2)
		{
			int cu = c2 - c1 + 1;
			FloatVector u = new FloatVector(cu);

			for (int j = c1; j <= c2; j++)
			{
				u[j - c1] = A[r, j];
				A[r, j] = 0.0f;
			}

			float norm = u.GetNorm();

			if (c1 == c2 || norm == 0)
			{
				A[r, c1] = -u[0];
				u[0] = (float)System.Math.Sqrt(2);
				return u;
			}

			float scale = 1.0f / norm;
			if (u[0] < 0.0f)
				scale *= -1.0f;

			A[r, c1] = -1.0f / scale;

			for (int j = 0; j < cu; j++)
			{
				u[j] *= scale;
			}

			u[0] += 1.0f;
			float s = (float)System.Math.Sqrt(1 / u[0]);

			for (int j = 0; j < cu; j++)
			{
				u[j] *= s;
			}
			return u;
		}
Ejemplo n.º 10
0
		public static FloatVector GenerateColumn(IFloatMatrix A, int r1, int r2, int c)
		{
			int ru = r2 - r1 + 1;
			FloatVector u = new FloatVector(r2 - r1 + 1);

			for (int i = r1; i <= r2; i++)
			{
				u[i - r1] = A[i, c];
				A[i, c] = 0.0f;
			}

			float norm = u.GetNorm();

			if (r1 == r2 || norm == 0)
			{
				A[r1, c] = -u[0];
				u[0] = (float)System.Math.Sqrt(2);
				return u;
			}

			float scale = 1.0f / norm;

			if (u[0] < 0.0f)
				scale *= -1.0f;

			A[r1, c] = -1.0f / scale;

			for (int i = 0; i < ru; i++)
			{
				u[i] = u[i] * scale;
			}

			u[0] = u[0] + 1.0f;
			float s = (float)System.Math.Sqrt(1 / u[0]);

			for (int i = 0; i < ru; i++)
			{
				u[i] = s * u[i];
			}
			return u;
		}