Integral from sin(x+y) from dx shows wierd result
34 views (last 30 days)
Show older comments
Penescu Vlad
on 31 May 2020
Commented: Penescu Vlad
on 1 Jun 2020
I have to integrate the function f = sin (x+y) giveing that a=0 and b = pi /2 ( the heads of the integral ) ... the normal answer should had been sin(y) + cos(y) but my result is (2^(1/2)*sin(y + pi/4)) ... I think the problem are the heads becouse if I simply do int(f,x) I get the right answer , but I put the head int(f,x,a,b) it show that weird result
2 Comments
Walter Roberson
on 31 May 2020
I get cos(y) + sin(y) when I try.
Can you post your code for testing ?
Accepted Answer
John D'Errico
on 31 May 2020
Edited: John D'Errico
on 31 May 2020
Computers don't really care that YOU think it looks wierd. The fact is, that form for the integral is correct, just as much so as the solution that you like. It may depend on your MATLAB release, of course, since with R2019b, I get:
syms x y
>> int(sin(x+y),x,0,pi/2)
ans =
cos(y) + sin(y)
However, if we recognize the trig identity:
sin(u + v) = sin(u)*cos(v) + cos(u)*sin(v)
Now consider what happens if u = y, and v = pi/4. Then
sin(y + pi/4) = sin(y)*cos(pi/4) + cos(y)*sin(pi/4)
But sin(pi/4) = cos(pi/4) = sqrt(2)/2. Therefore you should see that
cos(y) + sin(y) = 2/sqrt(2) * sin(y + pi/4) = sqrt(2)*sin(y + pi/4)
Same answer. You may think it is wierd. But at least your release of the symbolic toolbox decided it was a simple form to report the solution. In fact, it arguably is simpler, in the sense there is only one term in the solution. The solution you got was entirely valid, as was the alternative. Getting into the mind of a computer is sometimes difficult to know why it may choose any specific form for the solution.
5 Comments
madhan ravi
on 1 Jun 2020
Edited: madhan ravi
on 1 Jun 2020
+1.An impressive and detailed answer ;).
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!