Optimization for multi variables and mulit functions
77 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I've been working on an optimization for multi variables and mulit functions.
gamma1,gamma2,gamma3 are the functions that I want to optimize, and the variables will be a1,a2,a3. I want to use 'gamultiobj' as my optimization tool.
I've tried several ways but I keep getting error, I'm appreciate if someone is wiling to help!
Here's my code:
clear
Z01=50;
Z02=75;
v=3e+8;
section=10;
L=10;
a=L/section;
a0=50;
B1=0.4;
B2=1.6;
w1=2*pi*v*B1/L;
w2=2*pi*v*B2/L;
syms x w a1 a2 a3
beta=w/v;
% ABCD elements
for m=1:1:section
l=m*a;
Z0=a0+(a1*l)+(a2*(l^2))+(a3*(l^3));
A(m)=1;
B(m)=1i*Z0*sin(beta*a);
C(m)=1i*(1/Z0)*sin(beta*a);
D(m)=1;
end
% Turn into a cell array
for n=1:1:section
M{n}=[A(n) B(n) ; C(n) D(n)];
end
% Cascade each ABCD matrix
ABCD=M{1};
for m=2:1:section
ABCD=(ABCD)*(M{m});
end
ABCDcas=ABCD;
% Convert into S11
S11=((ABCDcas(1,2)-ABCDcas(2,1)*Z01*Z02)+((ABCDcas(1,1)*Z02)-(ABCDcas(2,2)*Z01)))/((ABCDcas(1,2)+ABCDcas(2,1)*Z01*Z02)+((ABCDcas(1,1)*Z02)+(ABCDcas(2,2)*Z01)));
gamma=(abs(S11));
gamma_edge=(1/abs(S11));
% Optimize objective
gamma1=vpa(subs(gamma_edge,w,w1),3);
gamma2=vpa(subs(gamma,w,(w1+w2)/2),3);
gamma3=vpa(subs(gamma_edge,w,w2),3);
function F = optfun(z)
2 comentarios
Torsten
el 21 de Ag. de 2023
Please state your problem in a mathematical notation. I don't understand your weird code.
Pooja Kumari
el 28 de Ag. de 2023
Editada: Pooja Kumari
el 28 de Ag. de 2023
Variable "z" is not defined. Can you specify the error. Could you provide the complete code for the optimization function optfun?
function F = optfun(z)
Respuestas (1)
Yash
el 4 de Sept. de 2023
Hi Guan,
I understand that you would like to use the 'gamultiobj' function for multi-variable and multi-function optimization. For this, you need to define an objective function that takes a vector of variables as input and returns a vector of objective function values.
Based on your code, it seems like you have already defined the objective functions 'gamma1', 'gamma2', and 'gamma3'. To use them in the 'gamultiobj' optimization, you can define an anonymous function as your objective function.
Here's an example of how you can modify your code:
gamma1 = @(a) vpa(subs(gamma_edge, [w a1 a2 a3], [w1 a(1) a(2) a(3)]), 3);
gamma2 = @(a) vpa(subs(gamma, [w a1 a2 a3], [(w1+w2)/2 a(1) a(2) a(3)]), 3);
gamma3 = @(a) vpa(subs(gamma_edge, [w a1 a2 a3], [w2 a(1) a(2) a(3)]), 3);
% Define the objective function to be optimized
objective = @(a) [gamma1(a), gamma2(a), gamma3(a)];
% Define the number of variables and their bounds
nvars = 3;
lb = [lower_bound1, lower_bound2, lower_bound3]; % Replace with appropriate lower bounds
ub = [upper_bound1, upper_bound2, upper_bound3]; % Replace with appropriate upper bounds
% Perform multi-objective optimization using gamultiobj
options = optimoptions('gamultiobj','Display','final');
[x,fval] = gamultiobj(objective, nvars, [], [], [], [], lb, ub, options);
In this example, the 'objective' function is defined as an anonymous function that takes a vector of variables 'a' as input and returns a vector of objective function values '[gamma1(a), gamma2(a), gamma3(a)]'. The 'nvars' variable represents the number of variables, and 'lb' and 'ub' represent the lower and upper bounds for each variable.
The 'gamultiobj' function performs the multi-objective optimization using the defined objective function and variable bounds. The resulting optimal variable values are stored in x, and the corresponding objective function values are stored in 'fval'.
Make sure to replace the placeholder values in the code with the appropriate values based on your specific problem and constraints.
I hope this helps you address the issue.
0 comentarios
Ver también
Categorías
Más información sobre Multiobjective Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!