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

5 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

回答(1 个)

Greg
Greg 2018-1-13
编辑:Greg 2018-1-13
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 个评论
John D'Errico
John D'Errico 2018-1-13
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by