Error when trying to use [I,m]=quad(fun, a, b, tol)

2 ビュー (過去 30 日間)
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa 2021 年 3 月 18 日
回答済み: Pratyush Roy 2021 年 3 月 22 日
Im trying to use the following line [I,m]=quad(g,0,1,1.0e-6) to get the number of nodes used and the aproximate value of the integral between 0 and 1 of g, which is g = exp(1).^x/(1+exp(1).^(2.*x)). but whenever I try to call the quad expression, I get the following:
Error using fcnchk (line 107)
If FUN is a MATLAB object, it must have an feval method.
Error in quad (line 57)
f = fcnchk(funfcn);

回答 (1 件)

Pratyush Roy
Pratyush Roy 2021 年 3 月 22 日
Hi,
If x is a symbolic variable, then the function g becomes a symbolic expression. In such cases, you should consider converting the expression to a function handle using the matlabFunction command.
You can also use the following code snippet for evaluating the nodes and approximate value of the integral
g = @(x)exp(1).^x./(1+exp(1).^(2.*x)) % "./" stands for element-wise division
[I,m]=quad(g,0,1,1.0e-6);
Hope this helps!

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by