Constraint set to be a real number
Ältere Kommentare anzeigen
I am using the fmincon for optimization. In the given problem one of the constraint should be strictly a real number. I did set the costraint as such
function [c,ceq] = constraint_cost(x)
% x = [0.69996 0.42986 0.14];
.
..
A_v(i,1) = AA(i,1) * r_e(i,1)^2 * n_tot(i,1) * n_e(i,1) * n_ion(i,1) * ((Z_e(i,1)* Z_ion(i,1))/Z) * p_e(i,1) * p_ion(i,1);
end
AV_constraint_1 = isreal(A_v);
AV_constraint_2 = isnan(A_v);
c(1) = double(AV_constraint_1);
c(2) = double(AV_constraint_2);
ceq =[];
c =[c(1) c(2)];
and in the main script I use this
A = [];
b = [];
Aeq =[];
beq = [];
c =[1 0];
lb = [0.02 0.02 0.14 ];
ub = [1 0.8 0.7];
equality =@constraint_cost;
I want the c = [] to be strictly [1 0] which implies A_v is a real number. And the following didnt work for me. Is there another way to implement this ?
2 Kommentare
Walter Roberson
am 15 Dez. 2024
c =[c(1) c(2)] - [1 0];
possibly ?
neil vaz
am 15 Dez. 2024
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 15 Dez. 2024
1 Stimme
The outputs from the nonlinear constraint function should not be boolean values. They should be continuous values.
Try making your nonlinear constraint function return imag(A_v) as the ceq output. This will try to satisfy the constraint that imag(A_v) == 0 which would require A_v to be real (or I believe have an imaginary part smaller than the constraint tolerance.)
2 Kommentare
neil vaz
am 15 Dez. 2024
Walter Roberson
am 15 Dez. 2024
You must use
function [c,ceq] = constraint_cost(x)
If appropriate you can set
c = [];
Kategorien
Mehr zu Nonlinear Optimization finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!