public HighOrderComplexRationalPolynomial(FirstOrderComplexRationalPolynomial uni) { int numerCount = 1; if (1 == uni.NumerDegree()) { numerCount = 2; } numer = new WWComplex[numerCount]; for (int i = 0; i < numerCount; ++i) { numer[i] = uni.N(i); } int denomCount = 1; if (1 == uni.DenomDegree()) { denomCount = 2; } denom = new WWComplex[denomCount]; for (int i = 0; i < denomCount; ++i) { denom[i] = uni.D(i); } }
Mul(FirstOrderComplexRationalPolynomial lhs, FirstOrderComplexRationalPolynomial rhs) { // 分子の項 p 分子の項 var n2 = WWComplex.Mul(lhs.N(1), rhs.N(1)); var n1 = WWComplex.Add(WWComplex.Mul(lhs.N(1), rhs.N(0)), WWComplex.Mul(lhs.N(0), rhs.N(1))); var n0 = WWComplex.Mul(lhs.N(0), rhs.N(0)); // 分母の項 p 分母の項 var d2 = WWComplex.Mul(lhs.D(1), rhs.D(1)); var d1 = WWComplex.Add(WWComplex.Mul(lhs.D(1), rhs.D(0)), WWComplex.Mul(lhs.D(0), rhs.D(1))); var d0 = WWComplex.Mul(lhs.D(0), rhs.D(0)); return(new SecondOrderComplexRationalPolynomial(n2, n1, n0, d2, d1, d0)); }
Add(FirstOrderComplexRationalPolynomial L, FirstOrderComplexRationalPolynomial R) { /* nL nR * p+2 p+4 * ─── + ──── * p+1 p+3 * dL dR * * nL dR nR dL * 分子 = (p+2)(p+3) + (p+4)(p+1) = (p^2+5x+6) + (p^2+5x+4) = 2x^2+10x+10 * 分子の次数 = 2 * * dL dR * 分母 = (p+1)(p+3) = p^2 + (1+3)p + 1*3 * 分母の次数 = 2 */ // 分子の項 var n2 = WWComplex.Add( WWComplex.Mul(L.N(1), R.D(1)), WWComplex.Mul(R.N(1), L.D(1))); var n1 = WWComplex.Add( WWComplex.Add(WWComplex.Mul(L.N(0), R.D(1)), WWComplex.Mul(L.N(1), R.D(0))), WWComplex.Add(WWComplex.Mul(R.N(0), L.D(1)), WWComplex.Mul(R.N(1), L.D(0)))); var n0 = WWComplex.Add( WWComplex.Mul(L.N(0), R.D(0)), WWComplex.Mul(R.N(0), L.D(0))); // 分母の項 var d2 = WWComplex.Mul(L.D(1), R.D(1)); var d1 = WWComplex.Add(WWComplex.Mul(L.D(0), R.D(1)), WWComplex.Mul(L.D(1), R.D(0))); var d0 = WWComplex.Mul(L.D(0), R.D(0)); return(new SecondOrderComplexRationalPolynomial(n2, n1, n0, d2, d1, d0)); }
Add(HighOrderComplexRationalPolynomial lhs, FirstOrderComplexRationalPolynomial rhs) { /* nL nR * p^2+2x+2 p+4 * ───────── + ──── * p^2+ p+1 p+3 * dL dR * * dL dR * 分母 = (p^2+p+1) (p+3) * 分母の次数 = degree(dL) + degree(dR) + 1 * * nL dR nR dL * 分子 = (p^2+2x+2)(p+3) + (p+4)(p^2+p+1) * 分子の次数 = degree(nL) + degree(dR) + 1 か degree(nR) * degree(dL) + 1の大きいほう */ ComplexPolynomial denomL; { var d = new WWComplex[lhs.DenomDegree() + 1]; for (int i = 0; i <= lhs.DenomDegree(); ++i) { d[i] = lhs.D(i); } denomL = new ComplexPolynomial(d); } ComplexPolynomial numerL; { var n = new WWComplex[lhs.NumerDegree() + 1]; for (int i = 0; i <= lhs.NumerDegree(); ++i) { n[i] = lhs.N(i); } numerL = new ComplexPolynomial(n); } // 分母の項 ComplexPolynomial denomResult; { var denomX = new ComplexPolynomial(new WWComplex[0]); if (1 == rhs.DenomDegree()) { denomX = ComplexPolynomial.MultiplyC(ComplexPolynomial.MultiplyX(denomL), rhs.D(1)); } var denomC = ComplexPolynomial.MultiplyC(denomL, rhs.D(0)); denomResult = ComplexPolynomial.Add(denomX, denomC); } // 分子の項 ComplexPolynomial numerResult; { ComplexPolynomial numer0; { var numerX0 = new ComplexPolynomial(new WWComplex[0]); if (1 == rhs.DenomDegree()) { numerX0 = ComplexPolynomial.MultiplyC(ComplexPolynomial.MultiplyX(numerL), rhs.D(1)); } var numerC0 = ComplexPolynomial.MultiplyC(numerL, rhs.D(0)); numer0 = ComplexPolynomial.Add(numerX0, numerC0); } ComplexPolynomial numer1; { var numerX1 = new ComplexPolynomial(new WWComplex[0]); if (1 == rhs.NumerDegree()) { numerX1 = ComplexPolynomial.MultiplyC(ComplexPolynomial.MultiplyX(denomL), rhs.N(1)); } var numerC1 = ComplexPolynomial.MultiplyC(denomL, rhs.N(0)); numer1 = ComplexPolynomial.Add(numerX1, numerC1); } numerResult = ComplexPolynomial.Add(numer0, numer1); } return(new HighOrderComplexRationalPolynomial(numerResult.ToArray(), denomResult.ToArray())); }