# Expressing fomula in terms of Tan instead of Cos and Sin

I have the following formula in Mathematica:

$$\frac{c \rho S \left(\text{Z0} \cos \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)+i c \rho S \sin \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)\right)}{c \rho S \cos \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)+i \text{Z0} \sin \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)}$$

Code:

(c S \[Rho] (Z0 Cos[(5 (1 + 2 n) \[Pi] x)/(6 a + 10 L)] +
I c S \[Rho] Sin[(5 (1 + 2 n) \[Pi] x)/(6 a + 10 L)]))/(
c S \[Rho] Cos[(5 (1 + 2 n) \[Pi] x)/(6 a + 10 L)] +
I Z0 Sin[(5 (1 + 2 n) \[Pi] x)/(6 a + 10 L)])


I would like to manipulate it in Mathematica by dividing the numerator and denominator by $$\cos \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)$$ so that I get the same expression in terms of two Tan functions. Is there an easy way to do this? I've had a good look in the docs and can't seem to find anything!

• Almost the same as Nasser's answer, but expressed in another form: expression /. Sin[x_] :> Hold[Tan[x]] Cos[x] // Simplify // ReleaseHold, so we introduce Tan but keep it from evaluation when Cos is cancelled during Simplify.
– Alx
Apr 3, 2020 at 13:26

I like to use ComplexityFunction when possible. For example, this seemed to work well in this case:

FullSimplify[expr,
ComplexityFunction ->
Function[e,
100 Count[e, _Cos | _Sin | E, {0, Infinity}] -
10 Count[e, _Tan, {0, Infinity}] + LeafCount[e]]]


$$\frac{c \rho S \left(\text{Z0}+i c \rho S \tan \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)\right)}{c \rho S+i \text{Z0} \tan \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)}$$

May be there is an easier way to automate this, but will let someone else figure it out.

Here is my attempt

expr = (c S ρ (Z0 Cos[(5 (1 + 2 n) π x)/(6 a + 10 L)] +
I c S ρ Sin[(5 (1 + 2 n) π x)/(6 a +
10 L)]))/(c S ρ Cos[(5 (1 + 2 n) π x)/(6 a +
10 L)] + I Z0 Sin[(5 (1 + 2 n) π x)/(6 a + 10 L)]);


Now

divid = Cos[(5 (1 + 2 n) π x)/(6 a + 10 L)];
Expand@(Numerator[expr]/divid)/Expand@(Denominator[expr]/divid)


$$\frac{c \rho S \text{Z0}+i c^2 \rho ^2 S^2 \tan \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)}{c \rho S+i \text{Z0} \tan \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)}$$

expr = (c S ρ (Z0 Cos[(5 (1 + 2 n) π x)/(6 a + 10 L)] +
I c S ρ Sin[(5 (1 + 2 n) π x)/(6 a +
10 L)]))/(c S ρ Cos[(5 (1 + 2 n) π x)/(6 a +
10 L)] + I Z0 Sin[(5 (1 + 2 n) π x)/(6 a + 10 L)]);

Divide @@ Expand[NumeratorDenominator[expr]/Cos[(5 (1 + 2 n) π x)/(6 a + 10 L)]]


$$\frac{c \rho S \text{Z0}+i c^2 \rho ^2 S^2 \tan \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)}{c \rho S+i \text{Z0} \tan \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)}$$

expr = (c S ρ (Z0 Cos[(5 (1 + 2 n) π x)/(6 a + 10 L)] +
I c S ρ Sin[(5 (1 + 2 n) π x)/(6 a + 10 L)])) /
(c S ρ Cos[(5 (1 + 2 n) π x)/(6 a + 10 L)] +
I Z0 Sin[(5 (1 + 2 n) π x)/(6 a + 10 L)]);

exp2 = Cos[(5 (1 + 2 n) π x)/(6 a + 10 L)];

exp2 FullSimplify[expr / exp2]

(c S ρ (Z0 + I c S ρ Tan[(5 (1 + 2 n) π x)/(6 a + 10 L)])) /
(c S ρ + I Z0 Tan[(5 (1 + 2 n) π x)/(6 a + 10 L)])

TeXForm @ %


$$\Large\frac{c \rho S \text{Z0}+i c^2 \rho ^2 S^2 \tan \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)}{c \rho S+i \text{Z0} \tan \left(\frac{5 \pi (2 n+1) x}{6 a+10 L}\right)}$$

I think that the following will do what you want

expr /. {Cos[y_] :> cos[y], Sin[y_] :> Tan[y] cos[y]} // Simplify


in this particular simple case. If cos[] appears in the simplified expression, then use % ./ cos[y_] :> Cos[y] to restore it.