/// <summary> /// /// </summary> /// <param name="sf">sin function</param> /// <param name="cf">cos function</param> /// <param name="sp">sin power</param> /// <param name="cp">cos power</param> /// <returns></returns> private static ExComp SinCosTrig(SinFunction sf, CosFunction cf, int sp, int cp, string dispStr, AlgebraComp dVar, ref EvalData pEvalData) { if (!sf.GetInnerEx().IsEqualTo(cf.GetInnerEx())) return null; bool spEven = sp % 2 == 0; bool cpEven = cp % 2 == 0; if (spEven && !cpEven) { // Use cos^2(x) = 1 - sin^2(x) ExComp subbedCos = PowOp.StaticCombine( SubOp.StaticCombine( ExNumber.GetOne(), PowOp.StaticCombine(new SinFunction(cf.GetInnerEx()), new ExNumber(2.0))), new ExNumber((cp - 1) / 2)); subbedCos = MulOp.StaticCombine(cf, MulOp.StaticCombine(PowOp.StaticCombine(sf, new ExNumber(sp)), subbedCos)); pEvalData.GetWorkMgr().FromFormatted(WorkMgr.STM + dispStr + " = \\int ( " + WorkMgr.ToDisp(subbedCos) + " ) d" + dVar.ToDispString() + WorkMgr.EDM, "Use the identity " + WorkMgr.STM + "cos^{2}(x)=1-sin^{2}(x)" + WorkMgr.EDM); return subbedCos; } else if (!spEven && cpEven) { // Using sin^2(x) = 1 - cos^2(x) ExComp subbedCos = PowOp.StaticCombine( SubOp.StaticCombine( ExNumber.GetOne(), PowOp.StaticCombine(new CosFunction(sf.GetInnerEx()), new ExNumber(2.0))), new ExNumber((sp - 1) / 2)); subbedCos = MulOp.StaticCombine(sf, MulOp.StaticCombine(PowOp.StaticCombine(cf, new ExNumber(cp)), subbedCos)); pEvalData.GetWorkMgr().FromFormatted(WorkMgr.STM + dispStr + " = \\int ( " + WorkMgr.ToDisp(subbedCos) + " ) d" + dVar.ToDispString() + WorkMgr.EDM, "Use the identity " + WorkMgr.STM + "sin^{2}(x)=1-cos^{2}(x)" + WorkMgr.EDM); return subbedCos; } else if (spEven && cpEven) { // Using sin^2(x) = (1/2)(1-cos(2x)) // Using cos^2(x) = (1/2)(1+cos(2x)) ExComp sinSub = MulOp.StaticCombine( AlgebraTerm.FromFraction(ExNumber.GetOne(), new ExNumber(2.0)), SubOp.StaticCombine(ExNumber.GetOne(), new CosFunction(MulOp.StaticCombine(new ExNumber(2.0), sf.GetInnerEx())))); ExComp cosSub = MulOp.StaticCombine( AlgebraTerm.FromFraction(ExNumber.GetOne(), new ExNumber(2.0)), AddOp.StaticCombine(ExNumber.GetOne(), new CosFunction(MulOp.StaticCombine(new ExNumber(2.0), sf.GetInnerEx())))); ExComp finalEx = MulOp.StaticCombine( PowOp.StaticCombine(sinSub, new ExNumber(sp / 2)), PowOp.StaticCombine(cosSub, new ExNumber(cp / 2))); pEvalData.GetWorkMgr().FromFormatted(WorkMgr.STM + dispStr + "=" + WorkMgr.ToDisp(finalEx) + WorkMgr.EDM, "Use the identities " + WorkMgr.STM + "sin^2(x)=\\frac{1}{2}(1-cos(2x))" + WorkMgr.EDM + " and " + WorkMgr.STM + "cos^2(x)=\\frac{1}{2}(1+cos(2x))" + WorkMgr.EDM); return finalEx; } return null; }