Пример #1
0
        internal static Term Parse(string termString)
        {
            if (string.IsNullOrWhiteSpace(termString))
            {
                throw new ArgumentException();
            }

            string input = termString.Replace(" ", "");

            if (string.IsNullOrWhiteSpace(input))
            {
                throw new ArgumentException();
            }

            string[] parts = input.Split(new char[] { '*' });

            Complex coefficient = Complex.One;

            if (parts[0].All(c => c == '-' || char.IsDigit(c)))
            {
                coefficient = new Complex(double.Parse(parts[0]), 0);
                parts       = parts.Skip(1).ToArray();
            }
            else if (parts[0].StartsWith("-") && parts[0].Any(c => char.IsLetter(c)))
            {
                coefficient = new Complex(-1, 0);
                parts[0]    = parts[0].Replace("-", "");
            }

            Indeterminate[] variables = parts.Select(str => Indeterminate.Parse(str)).ToArray();

            return(new Term(coefficient, variables));
        }
Пример #2
0
 public void SetIndeterminateValues(List <Tuple <char, Complex> > indeterminateValues)
 {
     foreach (Tuple <char, Complex> indeterminateValue in indeterminateValues)
     {
         var matches = Variables.Where(indt => indt.Symbol == indeterminateValue.Item1);
         if (matches.Any())
         {
             Indeterminate match = matches.Single();
             match.SetValue(indeterminateValue.Item2);
         }
     }
 }