# Matlab's quad equals 0 when over 0 to 6 and actual value over 3 to 5

1 回表示 (過去 30 日間)
Herje Wåhlén 2017 年 9 月 12 日
コメント済み: dpb 2017 年 9 月 12 日
I am to use Matlab's quad to find the integration of a function over 0 to 6. Using quad over that region I get the value 0, which is incorrect. If I try quad over 3 to 5 it gives me the actual value, which is around 0.2836.
format long
y = @(x) 80.*(exp(-((x-pi)./0.002).^2))
x = 0:10^(-5):6;
y = 80.*(exp(-((x-pi)./0.002).^2));
plot(x,y)
axis([ 3.13 3.15 0 100 ])
I plot the function to make sure it's correctly typed into Matlab.
What's going on here and how can I correct this?
Thank you / Herje

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

### 採用された回答

Teja Muppirala 2017 年 9 月 12 日
First, QUAD is very outdated, INTEGRAL (introduced in R2012a) is recommended instead.
The actual "bump" that you are integrating is very limited in range, around 3.13 to 3.15. When you integrate from 0 to 6, INTEGRAL might just see the whole thing as very nearly zero because it just happens to miss the nonzero part when its evaluating the function.
You can call INTEGRAL with the "waypoints" option and break up the region into smaller parts to help it out a bit.
format long
y = @(x) 80.*(exp(-((x-pi)./0.002).^2))
s_int = integral(y,0,6,'Waypoints',0:0.1:6)
s_int =
0.283592616151554
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
dpb 2017 年 9 月 12 日
Specifically, look at
>> x=linspace(3,4,1000);
>> yh=y(x);
>> semilogy(x,yh)
Note the magnitudes on the y axis...

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

### カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by