MATLAB: Integral from sin(x+y) from dx shows wierd result

integralsMATLAB

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

Best Answer

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.
Related Question