Application Center - Maplesoft

# Classroom Tips and Techniques: A Vexing Trig Conversion

You can switch back to the summary page by clicking here.

Classroom Tips and Techniques: A Vexing Trig Conversion

Robert J. Lopez

Emeritus Professor of Mathematics and Maple Fellow

Maplesoft

Introduction

In engineering, it is common to express the sum

in the form

where and .  Expressions like this often arise in the solution of initial value problems for damped oscillators, so the transformation is really useful for extracting the magnitude and phase shift of the oscillations.  Unfortunately, Maple does not presently provide a built-in facility for making this transformation.

In [1], I explored use of Maple's solve/identity construct to effect the transformation in Maple V Release 4, the extant version of Maple at that time (1996).  A year later in [2], Dr. Michael Monagan followed up on this question, and provided a procedure for the transformation, and applied it to

the solution of the IVP , obtaining

It's not clear from the article which version of Maple was used, but the conclusion, that Maple converted the cosine to a sine resulted in his writing

"Ugghhh!  Maple has simplified the cosine to a sine on us.  It has made the transformation thinking that we'd prefer the result with a positive angle."

We revisit both approaches, then add another alternative to the mix.

Initializations

The 1996 solve/identity Approach

To convert

 (3.1)

to the form

 (3.2)

use the Maple command

 (3.3)

The solution with positive amplitude is the desired one, and results in the form

 (3.4)

This is essentially the same approach as in [1], but no longer is it necessary to expand with all the concomitant difficulties of keeping and from themselves expanding in powers of and .

As an update to the calculation, I would like Maple to determine the coefficient of in the exponential, and , the value of angular frequency in the cosine and sine terms.  To this end, try to match against a more general template via the command

 Warning, solutions may have been lost

Unfortunately, this does not work, and even setting the environment variable to true does not change the outcome.  Hence, we revisit Monagan's code to see if it is more robust than the solve/identity device.

Monagan's 1997 Code

In [2], Monagan goes through several iterations of a procedure designed to morph to , thinking out loud as to why he makes the various modifications shown.  The result is the pair of procedures given in Table 1, where the second procedure invokes the first.

 Table 1   Monagan's procedures from [2] that morph to

Applying the trigcombine procedure, we have

 (4.1)

The earlier version of Maple used for [2] returned this as , prompting Monagan's Ugghhh!  However, even though Maple 12 now returns the cosine, as expected, one still has to include the extra argument, .  In return, we note that this procedure is robust enough to convert the generic

 (4.2)

to

Maple 12 in 2008

Monagan's code in the right-hand column of Table 1 uses the coeff command to obtain the coefficients of the trig terms.  However, for this to work, the trig terms must have arguments, which is why the trigcombine command requires the second argument, .  We sought code that would deduce this argument.  Dr. James McCarron, one of the Maple developers, provided that code and a lot more in the procedure TrigCombine, defined in the Code Edit Region below.

To access the procedure TrigCombine, click the button

To view the code in this Code Edit Region, use Context Menu: Expand Code Edit Region.  The code is work worthy of one of the Maple developers.  It finds the appropriate trig terms in larger expressions, and applies the requisite transformation in every instance possible in the given expression.

The TrigCombine procedure evolved from the desire to write

 (5.1)

in the form

without having to retype the argument of the trig functions.  Monagan's trigcombine returns unevaluated because of the "+1" in . Application of the TrigCombine procedure then gives

Like Monagan's trigcombine procedure, TrigCombine is robust enough to work with parameters, as we see from

It is even robust enough to find multiple instances of trig terms that need to be combined.  For example, if we apply TrigCombine to an expression such as

 (5.2)

we would get

in distinction from Monagan's trigcombine which would return unevaluated on .  It is not an inconvenience to include the independent variable as an argument to the TrigCombine command.  However, it is anticipated that in a future release of Maple, this functionality will be realized as an option to the convert command, with syntax something like

where the option "phaseamp" refers to the phase-amplitude form of the trig expressions we have been examining.

Monagan's "Ugghhh"

In [2], Monagan expressed great disappointment when Maple returned where he expected .  In fact, entering the latter will always result in the former, as we see from

This is not the fault of Monagan's code, and it will not be the fault of the code in TrigCombine, where this conversion will continue to occur.  The conversion of the cosine to the sine has been and still is, an automatic simplification in Maple that cannot be blocked by the user.  Hence, application of TrigCombine to

 (6.1)

necessarily results in

 (6.2)

and not in .

References

[1] Tips for Maple Instructors, Robert J. Lopez, MapleTech, Vol. 3, No. 3, 1966, p. 41.

[2] Tips for Maple Users and Programmers, Michael B. Monagan, MapleTech, Vol. 4, No. 3, 1997, p. 13.

Legal Notice: The copyright for this application is owned by Maplesoft. The application is intended to demonstrate the use of Maple to solve a particular problem. It has been made available for product evaluation purposes only and may not be used in any other context without the express permission of Maplesoft.