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=26419)

poster 2019-12-14 20:13

如何在MATLAB中正确设置数值积分?
 
我正在寻找整合这个表达:

[IMG]https://i.stack.imgur.com/Txw2l.png[/IMG]

但是我似乎在设置功能时遇到问题。正如[URL="http://www.mathworks.com/help/techdoc/ref/quad.html"]该[/URL] MATLAB解释中概述的那样,我已经定义了一个名为'NDfx.m'的单独函数,如下所示:

function [ y ] = NDfx(x) y = (1/sqrt(2*pi))*exp(-.5*x^2); % Error occurs here end 但是,当我在主函数中调用它时,在上面的注释行中出现错误。我的主要功能如下:

function[P] = NormalDistro(u,o2,x) delta = xu; dev = abs((delta)/o2); % Normalizes the parameters entered into function P_inner = quad(@NDfx,-dev,dev); % Integrates function NDfx from -dev to dev (error here) P_outer = 1 - P_inner; % Calculation of outer bounds of the integral if delta > 0 P = P_inner + (P_outer/2); elseif delta < 0 P = P_outer/2; elseif dev == 0 P = .5; end end 我得到的具体错误是:
[INDENT] ==> mpower中的错误

输入必须是标量和方矩阵

[/INDENT]
[B]回答:[/B]

您已经正确设置了所有内容以进行集成。错误在于函数本身的定义中。将变量用于要集成的函数时,请使用“。”。 (句点)在将^和*类的运算符应用于变量时,必须先于它们:

function [y] = NDfx(x) y = (1/sqrt(2*pi))*exp(-.5*(x.^2)); end

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


所有时间均为北京时间。现在的时间是 05:01

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