Integrate question
10-18-2017, 09:56 PM
Post: #1
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
Integrate question
Example:
integrate(cos(2*x)^3*sin(2*x)^5,x);

Returns:
-1/16*cos(2*x)^8+1/6*cos(2*x)^6-1/8*cos(2*x)^4;

attempting to simplify to match CAS programs:
1. trigsin(-1/16*cos(2*x)^8+1/6*cos(2*x)^6-1/8*cos(2*x)^4);
2. ratnormal((-1)/16*sin(2*x)^8+1/12*sin(2*x)^6-1/48);

1/48*(-3*sin(2*x)^8+4*sin(2*x)^6-1)

By hand, I get:
-(3*sin(2*x)^8-4*sin(2*x)^6)/48 + constant

Both the prime CAS and xcas return the same result, wxMaxima agrees with my hand result. Where does CAS/xcas get the -1/48 value for the constant term?
10-18-2017, 10:29 PM
Post: #2
 P_R_S Junior Member Posts: 3 Joined: Oct 2017
RE: Integrate question
(10-18-2017 09:56 PM)DrD Wrote:  1/48*(-3*sin(2*x)^8+4*sin(2*x)^6-1)

By hand, I get:
-(3*sin(2*x)^8-4*sin(2*x)^6)/48 + constant

The two solutions looks exactly the same to me; what you call "+ constant" is the "+(-1)" on the prime result, "constant" can be whatever you like... Am I wrong?
10-19-2017, 02:27 AM
Post: #3
 webmasterpdx Senior Member Posts: 541 Joined: Sep 2015
RE: Integrate question
I got the same as you did, and I'm thinking the following. When integrating without limits in Xcas/Cas, it just gives you an algebraic result and you are to assume the + constant part yourself.
This means that if the result contains a constant term, it's still correct (it just reduces the constant term by that much...it's still a constant).
e.g. integrate(x^2,x) is 1/3 x^3 + constant, so if it gave you a result of 1/3 x^3 + 1 is just as valid as just 1/3 x^3. i.e. You can ignore the constant terms and replace by "+ constant".

I'm also curious though where it's getting the -1/48 from...
-Donald
10-19-2017, 10:11 AM
Post: #4
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
RE: Integrate question
I understand that a constant would be a part of the family of solutions. I was wondering how the CAS/xcas integration function gets that particular value. The example was from old notes, where the result didn't contain -1/48, as solved manually. The results aren't the same.
10-19-2017, 10:42 AM
Post: #5
 webmasterpdx Senior Member Posts: 541 Joined: Sep 2015
RE: Integrate question
XCas solution is:

-(1/2)(cos(2x)^8)/8 + (cos(2x)^6)/6 -(1/2)(cos(2x)^4)/4

FYI.
This means that xcas knows to remove constants from indefinite integral results.
10-19-2017, 10:49 AM
Post: #6
 webmasterpdx Senior Member Posts: 541 Joined: Sep 2015
RE: Integrate question
Interesting....it's the trigsin function that creates the 1/48 on XCas, and I see from your original post, it does it on yours too.
10-19-2017, 11:05 AM
Post: #7
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
RE: Integrate question
[quote='P_R_S' pid='81705' dateline='1508365756'
The two solutions looks exactly the same to me ... Am I wrong?
[/quote]

I want to prove that you are NOT wrong. Given just the example integral, how can the -1/48 constant term value be obtained, confirmed by using other, (non-related), devices, or manual approaches?
10-19-2017, 11:23 AM
Post: #8
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
RE: Integrate question
(10-19-2017 10:49 AM)webmasterpdx Wrote:  Interesting....it's the trigsin function that creates the 1/48 on XCas, and I see from your original post, it does it on yours too.

I used trigsin() because my manual solution was in terms of sin() factors, and the CAS result was in terms of cos() factors. This was an attempt to match the visual appearance of the result. Trig functions can explode into some pretty wild combinations, and of the six trig functions, not all are appreciated by the machine: (sec, cos, cot, are the bad guys). It only gets worse with the hyperbolics. This is a shame, in my opinion, because manual solutions to problems involving them, really benefit from these scorned functions. Especially, when identities are in play.

However, from a software programmer's point of view ... it is completely understandable. Writing code that considers all the different ways to represent a problem ... well, it wouldn't be fun!
10-19-2017, 11:25 AM
Post: #9
 webmasterpdx Senior Member Posts: 541 Joined: Sep 2015
RE: Integrate question
Wolfram Alpha has this solution...
(-72 cos(4 x) + 12 cos(8 x) + 8 cos(12 x) - 3 cos(16 x))/6144
10-19-2017, 12:00 PM
Post: #10
 parisse Senior Member Posts: 1,136 Joined: Dec 2013
RE: Integrate question
There is no "constant" in the original answer. The constant comes from the fact that you rewrite the expression in terms of other trigonometric functions. It is of course required since the rewriting command does not know that you are rewriting an antiderivative, which is defined up to a constant.
For the prefered trig functions, it's much simpler for a CAS program to reduce the number of possibilities, that's why functions like sec or csc are immediatly translated to cos and sin equivalents. Hyperbolic trig functions are not necessary since you don't escape the real domain if you rewrite them with exp (unlike trig functions).
I hope this is clear enough and that I will not have to explain this again and again:-)
10-19-2017, 01:01 PM
Post: #11
 webmasterpdx Senior Member Posts: 541 Joined: Sep 2015
RE: Integrate question
I figured out where the 1/48 comes from.
When expanding from cosine terms to sines, there are pi/2 terms in there and they result in constants that accumulate to 1/48. Note that if you put a value in for x like 0.58, you'll get the same value in the original result and the trigsin result iff you include the constant term.

Note, the wolfram alpha term can be obtained by using the tcollect() function on the original result.
10-19-2017, 01:26 PM
Post: #12
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
RE: Integrate question
[CAS]
a:=int(cos(2*x)^3*sin(2*x)^5,x); // From the original example, [CAS] var a becomes: -3*cos(2*x)^8+8*cos(2*x)^6-6*cos(2*x)^4)/48
b:=-(3*sin(2*x)^8-4*sin(2*x)^6)/48; // result obtained by hand, (and wxMaxima)

Testing for equivalency:
a-b; // -1/48, The constant that shows up within the [CAS] result.

I understand that the value stored in (var a) gets rewritten, but that -1/48 term makes comparing results troublesome.

1. How can a student learn to feel confident with this outcome?
2. How can real world automation applications reliably use this result? (In other words, an automatic process of some sort, that dynamically uses a computed result for control purposes).
10-19-2017, 02:12 PM
Post: #13
 webmasterpdx Senior Member Posts: 541 Joined: Sep 2015
RE: Integrate question
I set f:= result from integrate, and g:= result from trigsin() including the constant term (1/48).
Then calculate f(0.58) and g(0.58).....the result is the same.

Note that both the Prime CAS and wxMaxima results are correct if their differences are a constant, since it's an indefinite integral.
10-19-2017, 03:08 PM
Post: #14
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
RE: Integrate question
I like your analysis!

However, (and this part is the same as my last post):
[CAS]
a:=int(cos(2*x)^3*sin(2*x)^5,x); // From the original example, [CAS] var a becomes: -3*cos(2*x)^8+8*cos(2*x)^6-6*cos(2*x)^4)/48
b:=-(3*sin(2*x)^8-4*sin(2*x)^6)/48; // result obtained by hand, (and wxMaxima)

Now try this:
subst(a,x = 0.58)-subst(b,x = 0.58); // difference =−2.08333333333e−2

This demonstrates that they do not produce the same result, regardless of the difference being a constant, (OR any constant being valid for an indefinite integral).

Also, by hand, or the wxMaxima result is better than the CAS/xcas result, in that it recognizes that you can use ANY constant, not just one particular constant offered up by CAS, (-1/48, in this case).

Notice, these are simply 'as entered' examples, (no massaging attempts to format the results, this time). There is a constant bias on the [CAS] side, which needs to be modeled, if simulating a PLC, for example. The constants accumulate with multi-processing, so the output routine must chase the resulting error term.

-Dale-
10-19-2017, 05:03 PM (This post was last modified: 10-19-2017 05:22 PM by toshk.)
Post: #15
 toshk Member Posts: 193 Joined: Feb 2015
RE: Integrate question
(10-19-2017 03:08 PM)DrD Wrote:  I like your analysis!

However, (and this part is the same as my last post):
[CAS]
a:=int(cos(2*x)^3*sin(2*x)^5,x); // From the original example, [CAS] var a becomes: -3*cos(2*x)^8+8*cos(2*x)^6-6*cos(2*x)^4)/48
b:=-(3*sin(2*x)^8-4*sin(2*x)^6)/48; // result obtained by hand, (and wxMaxima)

Now try this:
subst(a,x = 0.58)-subst(b,x = 0.58); // difference =−2.08333333333e−2

This demonstrates that they do not produce the same result, regardless of the difference being a constant, (OR any constant being valid for an indefinite integral).

Also, by hand, or the wxMaxima result is better than the CAS/xcas result, in that it recognizes that you can use ANY constant, not just one particular constant offered up by CAS, (-1/48, in this case).

Notice, these are simply 'as entered' examples, (no massaging attempts to format the results, this time). There is a constant bias on the [CAS] side, which needs to be modeled, if simulating a PLC, for example. The constants accumulate with multi-processing, so the output routine must chase the resulting error term.

-Dale-
it is integration...so you can not evaluate about a point but an interval
the answers are the same. once you step outside the integration to use trig (modification). you are in algebra world hence the factor -1/48 as CAS showed
preval((1/48)*(-3*sin(2*x)^8+4*sin(2*x)^6),2,1)
preval((-1/16)*sin(2*x)^8+(1/12)*sin(2*x)^6-(1/48),2,1)
∫(cos(2*x)^3*sin(2*x)^5,x,1,2)
10-19-2017, 05:44 PM
Post: #16
 parisse Senior Member Posts: 1,136 Joined: Dec 2013
RE: Integrate question
(10-19-2017 01:26 PM)DrD Wrote:  I understand that the value stored in (var a) gets rewritten, but that -1/48 term makes comparing results troublesome.

1. How can a student learn to feel confident with this outcome?
2. How can real world automation applications reliably use this result? (In other words, an automatic process of some sort, that dynamically uses a computed result for control purposes).
DrD, before discussing supposed bugs, you should probably revise your math courses about integration. Antiderivatives are defined up to a constant and this constant vanishes when you integrate on an interval. This is not specific to maths by the way, potentials in physics are also defined up to a constant (well it's the same but in dimension not necessarily 1).
10-19-2017, 07:34 PM
Post: #17
 webmasterpdx Senior Member Posts: 541 Joined: Sep 2015
RE: Integrate question
I'm not saying the CAS and wxMaxima results are the same....they are equivalent! i.e. Let CAS result = f, wxMaxima = w. Then f = w + constant. It doesn't matter if f(x) != w(x) for a specific x, because it's an indefinite integral. That would only apply if you had a definite integral over the same interval.

I'm only saying that if g = trigsin(f), then g(x) = f(x) (nothing to do with wxMaxima).
This is where the constant comes from. When you expand f(x) into sins, you'll get some sin(pi/2) terms and this is where the 1/48 comes from.....i.e. It is correct.

Also, as long as f(x) = w(x) + constant, then both f(x) and w(x) are solutions to the INDEFINITE integral, and are thus correct answers.
10-20-2017, 12:54 PM
Post: #18
 roadrunner Senior Member Posts: 306 Joined: Jun 2015
RE: Integrate question
I have to agree with Dr D on this one. Try this:

hand:=-(3*sin(2*x)^8-4*sin(2*x)^6)/48

nothand:=∫(cos(2*x)^3*sin(2*x)^5,x)

then simplify(hand-nothand)

returns 1/48.

trigsin isn't even involved but there is a difference of 1/48.

10-20-2017, 02:50 PM
Post: #19
 webmasterpdx Senior Member Posts: 541 Joined: Sep 2015
RE: Integrate question
Both answers are correct. An indefinite integral has an undefined constant, so any constant terms can be ignored and the answer is still correct. It's INDEFINITE. It's only until you define the integral over an interval that it matters. Then the constant terms are cancelled out since it's f(x1) - f(x2) which eliminates all constant terms.
10-20-2017, 04:43 PM
Post: #20
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
RE: Integrate question
Something tells me not to pursue this further, but:

We all get the general idea.

Returning -1/48 as a constant is less accurate than returning: c=any constant, or omitting it entirely, because ... it is indefinite. It's less accurate because a specific constant is not the same as any constant.

It's important because further processing should not need to track that -1/48 specific constant. An example of why this is, is demonstrated by comparing the results between the hand method, and CAS, as shown, the difference is not zero!

If the difference is not zero, and the complexity of the problem is already confusing enough to someone trying to make sense of all this, frustration has just been added to the poor soul who wants a simple answer to a simple question, "is my hand calculation correct?" Well ... no, not according to CAS/xcas.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)