MATLAB: How to compute an integral of solutions derivated from fzero

numerical integrationsystem of equations

g = makedist('lognormal','mu',4.525,'sigma',0.4); % I define a variable (here n) that follow a probability of distribution g (lognormal distribution)
flHn=@(t,q,n,l)((((((1-t).*100.*(1+0,001.*n).*(1+q).^0,25).*((l.*(1-t))%%I define a function of 4 parameters: t,q,n,l
lHn=@(t,q,n)(fzero(@(l)(flHn(t,q,n,l)),3)); % lHn is the function of l(t,q,n) such that flHn(t,q,n,t)=0
faggregate_wHlHn = @(t,q) (quadgk((@(n)(lHn(t,q,n).*pdf(g,n))),0,Inf)); % this is the aggregate distribution of lHn
Finally I want to solve the following problem (in a function Fsolve separated):
x=[];% vecteur of endogeneous variables ;
x0=[0.1,0.2];% Make a starting guess at the solution
[x]=fsolve(@mafonction_test9,x0,options);
F=[ x(1)-(lHn(x(1),x(2))
b-(faverage_lHn(x(1),x(2)))
];
with b a global
the following message appears:
"Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 308)
elseif ~isfinite(fx) || ~isreal(fx)"
Error in quadgk/evalFun (line 331)
fx = FUN(x);
%% I think the problem come form the fact that I asked to matlab to solve an integral of many solutions LHn found with( fzero), but I do not Know how to deal with this. could you please help me?

Best Answer

q = quadgk(fun,a,b) attempts to approximate the integral of a scalar-valued function fun from a to b using high-order global adaptive quadrature and default error tolerances. The function y = fun(x) should accept a vector argument x and return a vector result y, where y is the integrand evaluated at each element of x.