public static FractionX operator *(FractionX a, FractionX b) { var c = new FractionX(a.Numberator * b.Numberator, a.Denominator * b.Denominator); c.Simplify(); return(c); }
// // public static FractionX operator +(FractionX a, FractionX b) { FractionX ret = new FractionX((IntX)(a.Numberator * b.Denominator + b.Numberator * a.Denominator), a.Denominator * b.Denominator); ret.Simplify(); return(new FractionX(ret.Numberator, ret.Denominator)); }
public PolynomialX Copy() { FractionX[] polynomial = new FractionX[Coefficients.Length]; for (int i = 0; i < polynomial.Length; i++) { polynomial[i] = Coefficients[i]; } return(new PolynomialX(polynomial)); }
//public void Round(int decimalPlaces) //{ // for (int i = 0; i < Width; i++) // for (int j = 0; j < Height; j++) // Elements[i, j] = Elements[i, j].Round(decimalPlaces); //} ///// <summary> ///// Throws exception if not a square matrix. ///// </summary> ///// <returns></returns> //public Polynomial FindCharacteristicPolynomial() //{ // if (Width != Height) // throw new Exception("Must be square matrix."); // //Method can be found at: https://en.wikipedia.org/wiki/Faddeev%E2%80%93LeVerrier_algorithm // FractionX[] c = new FractionX[Width + 1]; // c[0] = (FractionX)1; // var I = DiagonalMatrixX.IdentityMatrixX(Width); // var M = (MatrixX)I; // for (int i = 1; i < c.Length; i++) // { // //Console.WriteLine(); // //Console.WriteLine(M); // M = this * M; // c[i] = -1.0 / i * M.Trace(); // //Console.WriteLine(M); // //Console.WriteLine(c[i]); // if (i + 1 < c.Length) // M += c[i] * I; // } // Polynomial poly = new Polynomial(c.Length); // for (int i = 0; i < c.Length; i++) // poly[i] = c[c.Length - i - 1]; // return poly; //} FractionX Trace() { FractionX trace = (FractionX)0; for (int i = 0; i < Width; i++) { trace += this[i, i]; } return(trace); }
public FractionX F(FractionX x) { FractionX result = (FractionX)0; FractionX term = (FractionX)1; for (int i = 0; i < Coefficients.Length; i++) { result += Coefficients[i] * term; term *= x; } return(result); }
public PolynomialX DivideOutRoot(FractionX root) { var copy = Copy(); PolynomialX result = new PolynomialX(Coefficients.Length - 1); FractionX last = Coefficients[Coefficients.Length - 1]; result[result.Coefficients.Length - 1] = last; for (int i = Coefficients.Length - 3; i >= 0; i--) { copy[i + 1] += root * last; result[i] = last = copy[i + 1]; } return(result); }