MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   MATLAB-具有很少参数的函数积分 (https://www.labfans.com/bbs/showthread.php?t=26326)

poster 2019-12-14 20:13

MATLAB-具有很少参数的函数积分
 
我想问一下如何在MATLAB中计算以下积分。

integral( PN(x,m,s), x(-Inf,Inf) , m>0 , s>0. 我创建了一个功能文件pn ,它是:

function PN = pn(x,m,s) PN = exp(-(xm).^2 ./ (2*s.^2)) ./ sqrt(2*pi*s.^2); end 和脚本begin.m :

%ezplot(@(x)pn(x,0,1),[-3,3]) --> This is OK! quad(pn(x,m,s),x,-Inf,Inf) --> I can't manipulate this, I tried several ways. 积分的答案必须为“ 1”。



[B]回答:[/B]

quad和其他集成例程希望在其第一个插槽中有一个[URL="http://www.mathworks.com/help/techdoc/matlab_prog/f2-38133.html"]功能句柄[/URL] 。另外,该功能必须不包括矢量输入和返回矢量输出。要解决您的问题,请尝试执行此操作,

m=0; s=1; F = @(x) pn(x,m,s); % a function handle quadgk(F,-inf,inf) % quadgk excepts -inf to inf as limits 这应该做您想要的。



[url=https://stackoverflow.com/questions/4978626]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 04:56

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.