How to transfer additional parameters to the objective function when using fmincon to find the minimum value?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
The following picture shows my planning problem. I try to use the function 'fmincon' find the minimum value of the 'F'. Howecer, when I build the objective function F.m file,it's confusing to me. My objctive function have a known parameter matrix 'H' which was not input by keyboard. So I try to transfer it to the objctive function. But there is an error--'Too many input parameters.' in the processing. I want to know how to built the objective function inclouding additional parameters. Thank you very much.
The incorrect code(Matlab 2015b):
fun1=@(EB)fun;
A=double(vpa(dB_n));
b=[0.05
0.05
0.05];
Aeq=[];
beq=[];
lb=[];
ub=[];
nonlcon=@(EB)constraints;
options = optimoptions('fmincon','Algorithm','sqp');
[sol,Fval]=fmincon(fun1,EB_n,A,b,Aeq,beq,lb,ub,nonlcon,options,H); %‘EB’ represents varibles in the code.
The objective function:
function obj=fun(EB,H)
F=H*[EB(1)
EB(2)
EB(3)];
fx=F(1);
fy=F(2);
Fc=fx^2+fy^2;
obj=(norm(Fc,2));
end
I want to know how to deal with the problem.
Best wishes.
4 Kommentare
Walter Roberson
am 21 Jan. 2020
B_n = input('Enter a scalar value for B_n? ');
dB_n = input('Enter a scalar value for dB_n? ');
Hbm_n = input('Enter a scalar value for Hbm_n? ');
dHbm_n = input('Enter a scalar value for dHbm_n? ');
The point is that you need to assign some particular value to those variables, through whatever means is appropriate for your situation. You cannot just use
fun1 = @(EB) fun(EB, B_n, dB_n, hbm_n, dHbm_n);
if B_n, dB_n, hbm_n, dHbm_n are unknown.
If the idea is to minimize with EB, B_n, dB_n, hbm_n, dHbm_n all as parameters to be varied in order to achieve the minimum value, then a different approach is needed.
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!