fzero Operands to the || and && operators must be convertible to logical scalar values.

9 views (last 30 days)
I saw the other two posts on this community about this issue, and they are both dimensional issues. However, I believe I do not have a dimensional issue here in my problem but still get the same error message. I tried 'fsolve' and symbolic equation 'solve', none of them worked (for the former, I got the initial value as the solution, while for the latter, I got another error). I paste my whole codes here just for reference, but the issue comes from the last 3 lines. I would very much appreciate your help!
%% Exogenous parameters
gamma = 0.181;
zeta = 10.63;
nu = 4/3;
chi = 0.233;
pi_r = 0.55;
pi_n = 1 - pi_r;
A = 1;
alpha = 0.53;
a=alpha;
phi_0 = 0.4226;
tau = 0;
g = 0.0083;
phi_1 = phi_0;
%% Objective function
obj = @(x) -1*(pi_r*(log(x(1)) - zeta*x(2)^(1 + nu) / (1 + nu) + chi*log(x(5))) + ...
pi_n*(log(x(3)) - zeta*x(4)^(1 + nu) / (1 + nu) + chi*log(x(5))));
nonlcon = @nonlinear_cons;
A = [];
b = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
x0 = [0.13, 0.38, 0.185, 0.41, 0.1];
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(obj,x0,A,b,Aeq,beq,lb,ub,nonlcon);
lr = x(2);
ln = x(4);
mu = lambda.ineqnonlin;
func = @(p) p./ (1+p) - a./(1-a) .* ...
pi_r.*phi_1.*lr ./ (pi_n.*(a.*A.^(1 ./ a).*(1 - a)^((1-a) ./ a) ./ ...
(((1+p).*phi_1).^((1-a)./a))).*ln) .* (1/mu .* (zeta .* lr.^nu ./ phi_1) - 1);
p0 = 0.1;
solx = fzero(func,p0)
<stopping criteria details>
Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 327)
elseif ~isfinite(fx) || ~isreal(fx)
Error in simpleTax (line 55)
solx = fzero(func,p0)
  2 Comments
Hideto Koizumi
Hideto Koizumi on 1 Sep 2019
Thank you guys for your prompt reaction! It looks like I made a silly mistake in the definition of 'A' as discussed below! Sorry that I forgot to attach the 'nonlinear_cons.m' file!

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Sep 2019
A = [];
So A is empty.
func = @(p) p./ (1+p) - a./(1-a) .* ...
pi_r.*phi_1.*lr ./ (pi_n.*(a.*A.^(1 ./ a).*(1 - a)^((1-a) ./ a) ./ ...
(((1+p).*phi_1).^((1-a)./a))).*ln) .* (1/mu .* (zeta .* lr.^nu ./ phi_1) - 1);
The computation invovles A, but A is empty. Computations involving empty arrays almost always end up giving empty results.

More Answers (1)

Hideto Koizumi
Hideto Koizumi on 1 Sep 2019
Edited: Hideto Koizumi on 1 Sep 2019
@Walter Robinson, that was the problem, it was my silly mistake that I replaced A with empty set for the optimization and reused it for fzero. Now the problem is fixed, and the fzero runs!

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!