フィルターのクリア

How to insert values into parameter and not function

3 ビュー (過去 30 日間)
Nicolas Ochmann
Nicolas Ochmann 2017 年 8 月 18 日
コメント済み: Nicolas Ochmann 2017 年 8 月 18 日
Hi everybody,
I hope somebody can help me out: I want to create a constraint function for fmincon with an input x which comprises of six symbolic variables x1 - x6. The variable 'parameter' depends on x which is why I want to insert their values into 'parameter'. The only way I found out is to create a function as shown below:
function [c, ceq] = constraints(x)
load ('File.mat','parameter');
parameter_function = matlabFunction(parameter);
c(1) = abs(parameter_function(x)); %Constraint
ceq = [];
end
This, however, takes a lot of time to run the code and I am quite sure because of the function creation. For this reason I would like to ask if anybody knows a way to insert the x values into 'parameter' without needing to create the function.
Thanks in advance!
Nicolas
  6 件のコメント
Stephen23
Stephen23 2017 年 8 月 18 日
@Nicolas Ochmann: function handles can be passed as arguments, so there is no reason why you cannot generate that function and pass it as a parameter (see the links I gave).
Nicolas Ochmann
Nicolas Ochmann 2017 年 8 月 18 日
Perfect, thank you very much!!

サインインしてコメントする。

採用された回答

Matt J
Matt J 2017 年 8 月 18 日
編集済み: Matt J 2017 年 8 月 18 日
load ('File.mat','parameter');
parameter_function = matlabFunction(parameter);
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub, @(x) deal(parameter_function(x)^2 , [] ) )
  2 件のコメント
Matt J
Matt J 2017 年 8 月 18 日
You could also modify your constraints() function as below and call fmincon as follows:
load ('File.mat','parameter');
parameter_function = matlabFunction(parameter);
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub, @(x) constraints(x,parameter_function))
function [c, ceq] = constraints(x,phandle)
c=phandle(x).^2;
ceq=[];
Nicolas Ochmann
Nicolas Ochmann 2017 年 8 月 18 日
Thank you!!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by