Error using fmincon, Supplied objective function must return a scalar value.
Afficher commentaires plus anciens
I have written following matlab code using fmincon function,
x0=[0.5;0.5;]; %starting point
Aieq=[1,1;repmat([(-eta * Pt * my_norm(f', H_DL(:,i))), (my_norm(W(:,i)', H_UL(:,i)))],K,1);];
b=[1;repmat([0],K,1);]; %inequality constraint
Aeq=[]; beq=[]; %equality constraint
lb=[0;0;];ub=[1;1;]; %lower bound, upper bound
[tau,fun] = fmincon(@(tau) objecfun(tau,A,B,K,sigma_AP),x0,Aieq,b,Aeq,beq,lb,ub);
function [tau,fun] = objecfun(tau,A,B,K,sigma_AP)
for i=1:K
fn(i)=-log10(1+(A(i)*tau(0+1))/((B(i)*tau(0+1)) + tau(1+1)* sigma_AP));
end
fun=sum(fn);
end
function [val]= my_norm(F,H)
val=((sqrt(real(trace( (F * H)' * (F * H) ) ) ) )^2);
end
.
Please some one help me to solve the following error that I am obtaining while running the code.
Error using fmincon (line 639)
Supplied objective function must return a scalar value.
To run the above matlab code, when K=1, i can have only one value i=1, then parameter values can be taken as follows.
A=3.5153e+21;eta = 1;
H_DL = 1.0e+02 * [ 7.3460 + 2.3079i; 2.0984 - 3.5173i; 4.7202 + 0.6043i;];
H_UL = 1.0e+02 * [ 7.3460 + 2.3079i; 2.0984 - 3.5173i; 4.7202 + 0.6043i; ];
f =[ 1; 0; 0; ];
W =[ 1; 0; 0; ];
Pt = 1.0000e+10;
sigma_AP = 1;
Réponses (1)
I'm not quite sure about the details of your problem but I think you want to do something closer to this.
Note the objective function should just return the objective function value for a given value of the design variable, in your case I think that is tau
x0=[0.5;0.5;]; %starting point
Aieq=[1,1;repmat([(-eta * Pt * my_norm(f', H_DL(:,i))), (my_norm(W(:,i)', H_UL(:,i)))],K,1);];
b=[1;repmat([0],K,1);]; %inequality constraint
Aeq=[]; beq=[]; %equality constraint
lb=[0;0;];ub=[1;1;]; %lower bound, upper bound
[tau,fval] = fmincon(@(tau) objecfun(tau,A,B,K,sigma_AP),x0,Aieq,b,Aeq,beq,lb,ub);
function f= objecfun(tau,A,B,K,sigma_AP)
for i=1:K
fn(i)=-log10(1+(A(i)*tau(0+1))/((B(i)*tau(0+1)) + tau(1+1)* sigma_AP));
end
f=sum(fn);
end
Catégories
En savoir plus sur Systems of Nonlinear Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!