How to compute cost function for fmincon?

Hi all, I'm performing an optimization using fmincon as follows:
r=[0.22 9.94 0.08;
0.16 0.95 0.08;
0.07 0.87 0.08];
R = [0.49; 0.42; 0.19];
x = fmincon(@(x) norm(r*x-R)^2, ones(3,1)/3, [], [], ones(1,3), 1, zeros(3,1), []);
Here, I wan to use a cost function for this optimization.
where , and x is a vector of initial guess values.
Could you somebody help me with this?

1 件のコメント

Matt J
Matt J 2020 年 9 月 21 日
The cost function you have shown is vector-valued. Do you mean to minimize its Euclidean norm?

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

 採用された回答

Matt J
Matt J 2020 年 9 月 21 日
編集済み: Matt J 2020 年 9 月 21 日

1 投票

r=[0.22 9.94 0.08;
0.16 0.95 0.08;
0.07 0.87 0.08];
R = [0.49; 0.42; 0.19];
omega=0.1;
gamma=150;
fun=@(x) norm( (r*x-R) + omega*(1-tanh(x*gamma)-gamma*tanh(x-1) ) )^2 ;
x = fmincon(@(x) fun, ones(3,1)/3, [], [], ones(1,3), 1, zeros(3,1), []);

4 件のコメント

hinami
hinami 2020 年 9 月 21 日
Thanks, Matt, but I got an error:
"Error using fmincon (line 710)
FMINCON requires all values returned by functions to be of data type double."
How can I solve this error?
Matt J
Matt J 2020 年 9 月 21 日
Running this test,
clear
r=[0.22 9.94 0.08;
0.16 0.95 0.08;
0.07 0.87 0.08];
R = [0.49; 0.42; 0.19];
omega=0.1;
gamma=150;
fun=@(x) norm( (r*x-R) + omega*(1-tanh(x*gamma)-gamma*tanh(x-1) ) )^2 ;
funx0=fun(ones(3,1)/3)
should give the result,
funx0 =
291.1478
hinami
hinami 2020 年 9 月 21 日
Yes, this works fine.
hinami
hinami 2020 年 9 月 21 日
編集済み: hinami 2020 年 9 月 21 日
Now it works fine with
r=[0.22 9.94 0.08;
0.16 0.95 0.08;
0.07 0.87 0.08];
R = [0.49; 0.42; 0.19]
omega=0.1;
gamma=150;
x = fmincon(@(x) norm( r*x-R + omega*(1-tanh(x*gamma)-tanh((x-1)*gamma)) )^2, ones(3,1)/3, [], [], ones(1,3), 1, zeros(3,1), []);

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNonlinear Optimization についてさらに検索

質問済み:

2020 年 9 月 21 日

編集済み:

2020 年 9 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by