why does the integral of sin(x) from -pi to 0 in matlab 2017b gives 0 instead of -2?

3 Ansichten (letzte 30 Tage)
I'm trying to solve a simple integral but the software gives me a wrong answer. Please help me, I'm trying to calculate a lot of integrals but this problem doesn't let me to.
  10 Kommentare

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Greg
Greg am 13 Jan. 2018
Bearbeitet: Greg am 13 Jan. 2018
I would definitely submit this to tech support. I don't even need to recall my rusty calculus to know that the results should match in R2016b and R2017b (and I've confirmed as you all have that they don't...odd).
It does look like the desired value is returned in R2017b by:
vpaintegral(sin(x),x,-pi,0)
Not sure of all the differences between int and vpaintegral, though.
  1 Kommentar
John D'Errico
John D'Errico am 13 Jan. 2018
To me this feels like an error generated by the parser, but only TMW would know the true source of the error. It is definitely a bug and worth reporting as such. It might be a bugged special case inside int.
Interesting that SOME other intervals return a bug too. For example, if we add some positive integer multiple of 2*pi to the upper limit, it still returns 0.
syms x
int(sin(x),-pi,2*pi)
ans =
0
int(sin(x),-pi,12*pi)
ans =
0
(This still in R2017b.)
Surprisingly, this one does work:
int(sin(x),0,pi)
ans =
2
And it is not the fact that the lower limit was -pi.
int(sin(x),-pi,-2*pi)
ans =
-2
I tried a few similar cases, but cos(x) does not seem to bug out for any set of limits. I gave up quickly on cos though. It is also not the specific limits. so if you try a simpler kernel...
int(x,-pi,0)
ans =
-pi^2/2
There is no problem.
vpaintegral is a numerical integration tool, using a convergence tolerance. It should work much like the integral tool does, so an adaptive integration tool.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by