Exponential function produces error with integrate command
5 ビュー (過去 30 日間)
古いコメントを表示
Hello. I'm relatively new to Matlab, and I have the following problem which boils down from a larger, more complicated integral, but for now I am working with a simplified case. I believe that I have found the source of my problem.
I wrote
fun = @(x) (exp(x).*exp(-(x.^2)/2);
q = integral(fun,-1,Inf)
The value of q is then NaN.
Why is this the case? I evaluated this integral in Wolfram Alpha and received a number.
0 件のコメント
採用された回答
David Goodmanson
2020 年 12 月 7 日
編集済み: David Goodmanson
2020 年 12 月 7 日
Hi Ben
for large x, exp(x) overflows to infinity before the exp(-(x.^2)/2) factor has a chance to bring in down. Try completing the square in the exponent:
fun = @(x) exp(-((x-1).^2)/2)*exp(1/2)
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!