Пример #1
0
 //多项式的指数运算
 private bool Pow(MultinomialC a, MultinomialC b, out MultinomialC out1)
 {
     out1 = null;
     if (b.count == 0)
     {
         if (a.count == 0)
         {
             MessageBox.Show("不能计算0的0次幂");
             return false;
         }
         try
         {
             out1 = new MultinomialC(new MultinomialB(1));
         }
         catch (Exception)
         {
             Error = "内存空间不足";
             return false;
         }
         return true;
     }
     if (!b.IsNumber())
     {
         Error = "指数不能是多项式";
         return false;
     }
     if (a.count == 0)
     {
         try
         {
             out1 = new MultinomialC();
         }
         catch (Exception)
         {
             Error = "内存空间不足";
             return false;
         }
         return true;
     }
     if (a.IsNumber())
     {
         try
         {
             out1 = new MultinomialC(new MultinomialB(Math.Pow(a.Buf[0].coefficient, b.Buf[0].coefficient)));
         }
         catch (Exception)
         {
             Error = "内存空间不足";
             return false;
         }
         if (Double.IsNaN(out1.Buf[0].coefficient))
             return false;
         return true;
     }
     int n = (int)b.Buf[0].coefficient;
     if (n < 0)
     {
         Error = "多项式不能计算负数的幂";
         return false;
     }
     try
     {
         out1 = new MultinomialC(a);
     }
     catch (Exception)
     {
         Error = "内存空间不足";
         return false;
     }
     for (int i = 1; i < n; i++)
         out1 = MUL(out1, a);
     return true;
 }
Пример #2
0
 //多项式除以一个数值
 private bool Div(MultinomialC a, MultinomialC b, out MultinomialC out1)
 {
     out1 = null;
     try
     {
         out1 = new MultinomialC(a);
     }
     catch (Exception)
     {
         Error = "内存空间不足";
         return false;
     }
     if (b.count == 0)
     {
         Error = "0不能做除数";
         return false;
     }
     if (!b.IsNumber())
     {
         Error = "多项式不能做除数";
         return false;
     }
     if (out1.count == 0)
         return true;
     if (out1.IsNumber())
     {
         out1.Buf[0].coefficient /= b.Buf[0].coefficient;
         return true;
     }
     Double n = (int)b.Buf[0].coefficient;
     for (int i = 0; i < out1.count; i++)
         out1.Buf[i].coefficient /= n;
     return true;
 }