How i can minimize a function in Simulink?
12 views (last 30 days)
Show older comments
Hello everyone, I´m trying to solve one model in simulink. I´m looking for minimizing one objective function. I´m using a Matlab function to solve the minimization. Well, the objective to minimize is shown in the picture. I called the following function:
u = Par_optimo(Ba,vd,V);
This one should me the result of the minimization. The complete functions working are:
function [Par] = Par_optimo(Ba,vd,V)
% Utilizamos el comando fmincon para minimizar la función objetivo
lambda = 1e-6;
% FUNCION OBJETIVO
coder.extrinsic('Pc')
objectivo = @(x) norm(((Ba*x')-vd)) + lambda*Pc(x,V);
lb = [0 0 0 0 -100 -100 -100 -100]; % limite inferior variables
ub = [100 100 100 100 0 0 0 0]; % limite superior variables
Aineq = []; % Matriz desigualdades
bineq = []; % Vector desigualdades
Ae = []; % Matriz equivalencias
be = []; % Vector equivalencias
x0 = [0 0 0 0 0 0 0 0]; % Punto inicial del algoritmo
nonlinc = @res;
[Par] = zeros(8,1);
[Par] = fmincon(objectivo,x0,Aineq,bineq,Ae,be,lb,ub,nonlinc);
end
Pc
function Poc = Pc(x,V)
T = x;
K = 40000;
Reff = 0.312;
Potencia = zeros(8,1);
P = [-7.2888e-5 1.8023e-5 -0.0016099 0.057038 0.16446];
Pp = [3.5227e-6 -0.00061109 0.034213 0.010455];
for i = 1:4
P0(i) = (T(i)^2+K*Reff*T(i))/(K*Reff^2)*V(i);
R0(i) = P(1)*T(i)^4+P(2)*T(i)^3+P(3)*T(i)^2+P(4)*T(i)+P(5);
Potencia(i) = P0(i)/R0(i);
end
for i = 5:8
Pi(i) = (T(i)^2+K*Reff*T(i))/(K*Reff^2)*V(i-4);
Ri(i) = Pp(1)*T(i)^3+Pp(2)*T(i)^2+Pp(3)*T(i)+Pp(4);
Potencia(i) = - Pi(i)*Ri(i);
end
Poc = sum(Potencia);
end
Res
function [c,ceq] = res(x)
c = [];
ceq = [x(1)*x(5) x(2)*x(6) x(3)*x(7) x(4)*x(8)]';
I ask you if it posible use fmincon in simulink or there are other ways to minimize a function. I will be very pleased if someone could help me .
Answers (0)
See Also
Categories
Find more on Linear Least Squares 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!