示例#1
0
 public void Add(LinearEquation a)
 {
     if (a.size == n + 1)
     {
         listofcoef.Add(a);
     }
     else
     {
         throw new ArgumentException();
     }
 }
示例#2
0
        public override bool Equals(object obj)
        {
            LinearEquation a = (LinearEquation)obj;

            for (int i = 0; i < size; i++)
            {
                if (Math.Abs(listofcoef[i] - a[i]) > 0.000000001)
                {
                    return(false);                                              //17
                }
            }
            return(true);
        }
示例#3
0
        public static LinearEquation operator -(LinearEquation a, LinearEquation b)
        {
            LinearEquation a1 = new LinearEquation(a.listofcoef);

            for (int i = 0; i < a.size; i++)
            {
                a1[i] = a[i];
            }
            for (int i = 0; i < Math.Min(a.size, b.size); i++)
            {
                a1[i] -= b.listofcoef[i];
            }
            return(new LinearEquation(a1));
        }
示例#4
0
        public void StepConvert()
        {
            int    step;
            int    j;
            double step1, step2;

            for (int i = 0; i < size; i++)
            {
                j = i;
                if (listofcoef[i][j] == 0)
                {
                    while (listofcoef[i][j] == 0 && j < n)
                    {
                        j++;
                    }
                    step = 1;
                    while (i + step < size && listofcoef[i + step][j] == 0)
                    {
                        step++;
                    }
                    if (i + step == size)
                    {
                        return;
                    }
                    LinearEquation c = new LinearEquation(listofcoef[i]);
                    c                    = listofcoef[i];
                    listofcoef[i]        = listofcoef[i + step];
                    listofcoef[i + step] = c;
                }
                for (int k = i + 1; k < size; k++)
                {
                    step1          = listofcoef[i][j];
                    step2          = listofcoef[k][j];
                    listofcoef[k] *= step1;
                    listofcoef[k] -= listofcoef[i] * step2;
                }
            }
        }