I am using UseParallel
command to go for parallel computing in fmincon
as normal computation is taking a lot of time. But while using
np = 6
Cost = @(u)cost_min( u, CNT, u_in, y_in, Last );
options = optimoptions( 'fmincon', 'UseParallel', true );
[ufinal,fval,exitflag,output,grad] = fmincon( Cost, u, A, B, [], [], lb, ub, [], options );
function Cost = cost_min(u,CNT,u_in,y_in,Last)
global np
for i = 1
Costi(i) = (y(i) - yref(i))'*Q(i,i)*(y(i) - yref(i)) + (u(i)- u0)'*R(i,i)*(u(i)- u0);
end
for i = 2:np
Costi(i) = (y(i) - yref(i))'*Q(i,i)*(y(i) - yref(i)) + (u(i)- u(i-1))'*R(i,i)*(u(i)- u(i-1));
end
Cost = sum(Costi);
Simulink is showing the error
Size vector should be a row vector with real elements.
While without the UseParallel
option, the simulation is working fine.