I received the error message: Unable to perform assignment because the left and right sides have a different number of elements. Error in augLagFun>augLagScalarFun (line 175)
Show older comments
I am trying to solve an optimization problem where the number of constraints change from one point to another during the optimization. The function which defines the constraints is as follows. y_hat1, mspe1, y_hat2, and mspe2 are computed in the code. I deleted that part to simplify the code.
function [c,ceq] = non_linear_constraints(x,model1,model2,alpha_A,rhs,q,alpha_infe)
binding_output = check_binding_output_constraints(y_hat1,mspe1,y_hat2,mspe2,alpha_A,rhs,q);
ceq=[];
z_A = norminv(1-(alpha_A/2*(q-1)));
z_infe = norminv(1-(alpha_infe/(q-1)));
i=1;
if (sum(binding_output) > 0)
c=zeros(q-1+2*sum(binding_output),1);
if (binding_output(1) == 1)
c(i) = y_hat1 - z_A * sqrt(mspe1) - rhs(1);
i=i+1;
c(i) = -y_hat1 - z_A * sqrt(mspe1) + rhs(1);
i=i+1;
end
if (binding_output(2) == 1)
c(i) = y_hat2 - z_A * sqrt(mspe2) - rhs(2);
i=i+1;
c(i) = -y_hat2 - z_A * sqrt(mspe2) + rhs(2);
i=i+1;
end
c(i) = y_hat1 + z_infe * sqrt(mspe1) - rhs(1);
i=i+1;
c(i) = y_hat2 + z_infe * sqrt(mspe2) - rhs(2);
else
c=zeros(q-1,1);
c(i) = y_hat1 + z_infe * sqrt(mspe1) - rhs(1);
i=i+1;
c(i) = y_hat2 + z_infe * sqrt(mspe2) - rhs(2);
end
In that code, the sum of the components of the function binding_output gives the number of extra constraints (if there are any). So, the size of c changes from one point x to another point x during the iterations. I am solving the problem using patternsearch (which is a function in Matlab's optimization toolbox). But a similar error message occurs if I use fmincon.
I will be very pleased if you can help me to solve this problem. Thanks in advance.
Ebru
Accepted Answer
More Answers (0)
Categories
Find more on Problem-Based Optimization Setup 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!