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

7 ビュー (過去 30 日間)
Jorge Mera
Jorge Mera 2018 年 1 月 12 日
コメント済み: John D'Errico 2018 年 1 月 13 日
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 件のコメント
per isakson
per isakson 2018 年 1 月 13 日
編集済み: per isakson 2018 年 1 月 13 日
"I need it to work well" Thus contact Service Requests
Star Strider
Star Strider 2018 年 1 月 13 日
I wish I had posted that as an Answer!

サインインしてコメントする。

回答 (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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by