Make Mupad use trig identities to simplify integrations

Hello, here is my problem:
Integrals such as:
int(sinh(A*x)*sin(B*x),x)
or
int(sinh(A*x)*sin(B*x),x)
give very clear, easily coded solutions in MuPad. However
int(sinh(A*x)*sin(B*x)*cos(C*x),x)
generates a horrid solution involving terms such as sin(A x i), when it is clear as an integral of real functions on real variables the result should be real. (yes I have used assume(x, Type::Real)..)
By hand, there is a simple way to break down the third integral to a sum of the form of the first integral using sin(A)cos(B)=(sin(A+B)+sin(A-B))/2 i.e:
int(sinh(A*x)*(sin((B+C)*x)+sin((B-C)*x))/2,x)
but that still gives me a similarly horrible answer. In fact I have to seperate the integral entirely and by hand to
int(sinh(A*x)*sin((B+C)*x)/2,x)+int(sinh(A*x)*sin((B-C)*x)/2,x)
So my questions are:
1: Is it possible to get MuPad to do the trig conversion above automatically? I've only found functions to do the opposite so far.
2: Can integration be persuaded to keep the expanded/simplified form of these integrals so that it gives more elegant results?
Obviously the examples above are quite simple, but my problem involves many such terms in a bit of a 'worms nest', which all need expanding to fourier series coefficients, hence the form of the above equations and me wanting Mupad to save me a lot of time and possible error!

 Accepted Answer

I tried this out in Maple, and it has similar difficulties. The work-around I found in Maple was
t := int(EXPRESSION,x);
combine(convert(t,trig),trig);
Unfortunately I have not found the MuPad equivalent of Maple's combine(), and MuPad's equivalent of convert() are not as easy to access as in Maple.
For the record, the result I got was
(1/2)*(-2*A*B*C*cosh(A*x)*sin(B*x+C*x) + B^2*C*sinh(A*x)*cos(B*x+C*x) + C^2*B*sinh(A*x)*cos(B*x+C*x)+B^2*A*cosh(A*x)*sin(B*x+C*x) + 2*A*B*C*cosh(A*x)*sin(B*x-C*x) + C^2*A*cosh(A*x)*sin(B*x+C*x) - A^2*B*sinh(A*x)*cos(B*x+C*x) + C^3*sinh(A*x)*cos(B*x-C*x) - B^2*C*sinh(A*x)*cos(B*x-C*x) - B^3*sinh(A*x)*cos(B*x-C*x) - A^2*C*sinh(A*x)*cos(B*x+C*x) + A^2*C*sinh(A*x)*cos(B*x-C*x) - A^2*B*sinh(A*x)*cos(B*x-C*x) + A^3*cosh(A*x)*sin(B*x-C*x) + C^2*B*sinh(A*x)*cos(B*x-C*x) + C^2*A*cosh(A*x)*sin(B*x-C*x) - C^3*sinh(A*x)*cos(B*x+C*x) + B^2*A*cosh(A*x)*sin(B*x-C*x) - B^3*sinh(A*x)*cos(B*x+C*x) + A^3*cosh(A*x)*sin(B*x+C*x)) / (B^4+C^4+2*A^2*B^2+2*A^2*C^2-2*B^2*C^2+A^4)

1 Comment

This answer works well - which is ironic because I originally moved over to MuPad because it seemed to handle simpler trig products much better than Maple.
thanks

Sign in to comment.

More Answers (1)

variant
syms x A B C
int(subs(sinh(A*x)*sin(B*x)*cos(C*x),sinh(A*x),1/2*(exp(A*x)-exp(-A*x))),x)
or so
eval(['f1 = @(x,A,B,C)' vectorize(char(int(subs(sinh(A*x)*sin(B*x)*cos(C*x),sinh(A*x),1/2*(exp(A*x)-exp(-A*x))),x)))]);
>> f1(3,2,5,1)
ans =
-36.21
or so 2: idea of Walter Roberson, use Maple Toolbox for MATLAB:
Ex = int(sinh(A*x)*sin(B*x)*cos(C*x),x);
count = maple(['simplify(combine(convert(' char(Ex) ',trig),trig),size)'])
count =
2 2
1/2 (-(A + (C + B) ) (-C + B) sinh(x A) cos(x (-C + B))
2 2 2 2
+ A cosh(x A) (A + (C + B) ) sin(x (-C + B)) + (A + (-C + B) )
/
(-sinh(x A) (C + B) cos(x (C + B)) + cosh(x A) sin(x (C + B)) A)) /
/
2 2 2 2
((A + (-C + B) ) (A + (C + B) ))

1 Comment

Your first suggestion works well and seems to be the better answer for my purposes as it is straightforward to add the additional complexity I need and to integrate into Matlab - hopefully without typing any of the expressions out myself! It also avoids using Maple, which helps me when I work at home. It would be nice to stick to sinh/cosh notation but at this stage I am perfectly with exp if it gets the job done..
For my expression I had to apply 4 substitutions; for sinh and the equivalent in cosh each with two different operands.
It turns out I can only 'accept' one answer but this answer is just as good if not better!
thanks

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!