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

34 views (last 30 days)
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
Walter Roberson on 31 May 2020
I get cos(y) + sin(y) when I try.
Can you post your code for testing ?

Sign in to comment.

Accepted Answer

John D'Errico
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
madhan ravi on 1 Jun 2020
Edited: madhan ravi on 1 Jun 2020
+1.An impressive and detailed answer ;).
Penescu Vlad
Penescu Vlad on 1 Jun 2020
I got another way to do it I think ... by using expand(int(f,x,a,b)) it shows the answer the way I wanted ... But thanks for the explacations, it helped a lot

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!