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

1 view (last 30 days)
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);

Answers (1)

Pratyush Roy
Pratyush Roy on 22 Mar 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!

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!