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

조회 수: 1 (최근 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 CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by