Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa am 18 Mär. 2021
Beantwortet: Pratyush Roy am 22 Mär. 2021
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);

Antworten (1)

Pratyush Roy
Pratyush Roy am 22 Mär. 2021
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!

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by