/** * Calculates the cosine (cosinus) of {@link BigComplex} x in the complex domain. * * @param x the {@link BigComplex} to calculate the cosine for * @param mathContext the {@link MathContext} used for the result * @return the calculated cosine {@link BigComplex} with the precision specified in the <code>mathContext</code> */ public static BigComplex cos(this BigComplex x, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode()); return(BigComplex.valueOf( BigDecimalMath.cos(x.re, mc).multiply(BigDecimalMath.cosh(x.im, mc), mc).round(mathContext), BigDecimalMath.sin(x.re, mc).multiply(BigDecimalMath.sinh(x.im, mc), mc).negate().round(mathContext))); }
/** * Calculates the natural exponent of {@link BigComplex} x (e<sup>x</sup>) in the complex domain. * * <p>See: <a href="https://en.wikipedia.org/wiki/Exponential_function#Complex_plane">Wikipedia: Exponent (Complex plane)</a></p> * * @param x the {@link BigComplex} to calculate the exponent for * @param mathContext the {@link MathContext} used for the result * @return the calculated exponent {@link BigComplex} with the precision specified in the <code>mathContext</code> */ public static BigComplex exp(this BigComplex x, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode()); BigDecimal expRe = BigDecimalMath.exp(x.re, mc); return(BigComplex.valueOf( expRe.multiply(BigDecimalMath.cos(x.im, mc), mc).round(mathContext), expRe.multiply(BigDecimalMath.sin(x.im, mc), mc)).round(mathContext)); }
/** * Calculates {@link BigComplex} x to the power of {@link BigDecimal} y (x<sup>y</sup>). * * @param x the {@link BigComplex} value to take to the power * @param y the {@link BigDecimal} value to serve as exponent * @param mathContext the {@link MathContext} used for the result * @return the calculated x to the power of y with the precision specified in the <code>mathContext</code> */ public static BigComplex pow(this BigComplex x, BigDecimal y, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode()); BigDecimal angleTimesN = x.angle(mc).multiply(y, mc); return(BigComplex.valueOf( BigDecimalMath.cos(angleTimesN, mc), BigDecimalMath.sin(angleTimesN, mc)).multiply(BigDecimalMath.pow(x.abs(mc), y, mc), mc).round(mathContext)); }
/** * Returns a complex number with the specified polar {@link BigDecimal} radius and angle using the specified {@link MathContext}. * * @param radius the {@link BigDecimal} radius of the polar representation * @param angle the {@link BigDecimal} angle in radians of the polar representation * @param mathContext the {@link MathContext} used to calculate the result * @return the complex number */ public static BigComplex valueOfPolar(BigDecimal radius, BigDecimal angle, MathContext mathContext) { if (radius.signum() == 0) { return(ZERO); } return(valueOf( radius.multiply(BigDecimalMath.cos(angle, mathContext), mathContext), radius.multiply(BigDecimalMath.sin(angle, mathContext), mathContext))); }