コード例 #1
0
 public static Vector operator /(Vector one, double param)
 {
     Vector newV = new Vector(one);
     for (int i = 0; i < one.Dim; i++)
         newV[i] /= param;
     return newV;
 }
コード例 #2
0
 public static Vector operator *(Matrix one, Vector other)
 {
     if (one.Width != other.Dim)
         throw new Exception("Dim Error");
     Vector newV = new Vector(one.Height);
     for (int i = 0; i < newV.Dim; i++)
         newV[i] = other * one.Row(i);
     return newV;
 }
コード例 #3
0
        public Vector(Vector other)
        {
            field = new double[other.Dim];

            for (int i = 0; i < other.Dim; i++)
                field[i] = other[i];
        }
コード例 #4
0
 public static Vector operator -(Vector one, Vector other)
 {
     if (one.Dim != other.Dim)
         throw new Exception("Vector lengths aren't the same");
     Vector newV = new Vector(one);
     for (int i = 0; i < other.Dim; i++)
         newV[i] -= other[i];
     return newV;
 }
コード例 #5
0
 public void SetRow(int position, Vector row)
 {
     if (Width != row.Dim)
         throw new Exception("Dim Error");
     for (int i = 0; i < Width; i++)
         field[i, position] = row[i];
 }
コード例 #6
0
 public void SetColumn(int position, Vector column)
 {
     if (Height != column.Dim)
         throw new Exception("Dim Error");
     for (int i = 0; i < Height; i++)
         field[position, i] = column[i];
 }
コード例 #7
0
 /// <summary>
 /// Returns a row at the given postion as a vector, intial index is 0
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public Vector Row(int position)
 {
     Vector newV = new Vector(Width);
     for (int i = 0; i < Width; i++)
         newV[i] = field[i, position];
     return newV;
 }
コード例 #8
0
 /// <summary>
 /// Return a new matrix after GaussianElimination (row reduction) of the original matrix
 /// </summary>
 /// <returns></returns>
 public Matrix GaussianElimination()
 {
     //if (Height != Width)
     //    throw new Exception();
     Matrix newM = new Matrix(this);
     int position = -1;
     double param = 0;
     int count = 0;
     Vector positionV = new Vector(Width);
     for (int i = 0; i < Width; i++)
     {
         if (position != -1)
         {
             newM.SwitchRow(position, count);
             count++;
             position = -1;
         }
         for (int j = count; j < Height; j++)
         {
             if (newM.field[i, j] != 0)
             {
                 if (position != -1)
                     newM.SetRow(j, newM.Row(j) - positionV * newM[i, j] / param);
                 else
                 {
                     position = j;
                     param = newM[i, j];
                     newM.SetRow(j, newM.Row(j));
                     positionV = newM.Row(j);
                 }
             }
         }
     }
     return newM;
 }
コード例 #9
0
 /// <summary>
 /// Return a column at the given position as a vector, initial index is 0
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public Vector Column(int position)
 {
     Vector newV = new Vector(Height);
     for (int i = 0; i < Height; i++)
         newV[i] = field[position, i];
     return newV;
 }