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

9 views (last 30 days)
Hideto Koizumi on 31 Aug 2019
Commented: Hideto Koizumi on 1 Sep 2019
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];
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 CommentsShowHide 1 older comment
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!

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.
Hideto Koizumi on 1 Sep 2019
That was it! Thank you Walter! Btw, I like your profile pic, haha

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!