-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplexTerm.cs
52 lines (42 loc) · 1.12 KB
/
ComplexTerm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
namespace ExtendedArithmetic
{
public class ComplexTerm : IComplexTerm
{
public static ComplexTerm Zero = new ComplexTerm(Complex.Zero, 0);
public int Exponent { get; private set; }
public Complex CoEfficient { get; set; }
private static string IndeterminateSymbol = "X";
public ComplexTerm(Complex coefficient, int exponent)
{
Exponent = exponent;
CoEfficient = coefficient;
}
public static IComplexTerm[] GetTerms(Complex[] terms)
{
List<IComplexTerm> results = new List<IComplexTerm>();
int degree = 0;
foreach (Complex term in terms)
{
results.Add(new ComplexTerm(term, degree));
degree += 1;
}
return results.ToArray();
}
public Complex Evaluate(Complex indeterminate)
{
return Complex.Multiply(CoEfficient, Complex.Pow(indeterminate, Exponent));
}
public IComplexTerm Clone()
{
return new ComplexTerm(this.CoEfficient, this.Exponent);
}
public override string ToString()
{
return $"{CoEfficient.FormatString()}*{IndeterminateSymbol}^{Exponent}";
}
}
}