예제 #1
0
 public Term Clone()
 {
     Term f = new Term ();
     f.coefficient = coefficient;
     foreach (var variable in Variables) {
         f.Variables.Add (variable.Key, variable.Value);
     }
     return f;
 }
예제 #2
0
 /// <summary>
 /// Adds a term.
 /// eg. {2, x^2}, {4} + {-3, y}
 /// </summary>
 /// <param name="f">the term to be added.</param>
 public void Add(Term term)
 {
     foreach (var t in Terms) {
         if (t.VariablesToString ().Equals (term.VariablesToString ())) {
             t.Coefficient += term.Coefficient;
             return;
         }
     }
     Terms.Add (term);
 }
예제 #3
0
 /// <summary>
 /// Divides by a Term result is stored in current term.
 /// eg (2x / 3y)
 /// </summary>
 /// <param name="f">The term to be devided.</param>
 public void Divide(Term f)
 {
     Coefficient /= f.Coefficient;
     if (Coefficient == 0) {
         Variables = new SortedDictionary<string, decimal> ();
         return;
     }
     foreach (var variable in f.Variables)
         AddVariable (variable.Key, variable.Value * -1);
 }
예제 #4
0
 public Term(Term f)
 {
     Multiply (f);
 }
예제 #5
0
 public Factor(Term term)
 {
     Terms.Add (term);
 }
예제 #6
0
 /// <summary>
 /// Substracts a term.
 /// eg. {2, x^2}, {4} - {-3, y}
 /// </summary>
 /// <param name="term">The term to be substracted.</param>
 public void Subtract(Term term)
 {
     term.Coefficient *= -1;
     Add (term);
 }
예제 #7
0
 /// <summary>
 /// Multiply a Factor by a Term.
 /// eg. (2x) * (2x + 3y)
 /// </summary>
 /// <param name="term">The term to be multiplied.</param>
 public void Multiply(Term term)
 {
     foreach (var factor in Terms) {
         factor.Multiply (term);
     }
 }
예제 #8
0
 /// <summary>
 /// Divide by a term.
 /// eg 2x / (2x + 1)
 /// </summary>
 /// <param name="term">The term to be devided by.</param>
 public void Divide(Term term)
 {
     Term temp;
     foreach (var factor in Terms) {
         temp = term.Clone ();
         temp.Divide (factor);
         factor.Coefficient = temp.Coefficient;
         factor.Variables = temp.Variables;
     }
 }