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

1 visualización (últimos 30 días)
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa el 18 de Mzo. de 2021
Respondida: Pratyush Roy el 22 de Mzo. de 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);

Respuestas (1)

Pratyush Roy
Pratyush Roy el 22 de Mzo. de 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!

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by