How to compute cost function for fmincon?

조회 수: 7 (최근 30일)
hinami
hinami 2020년 9월 21일
편집: hinami 2020년 9월 21일
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일
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일
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개)

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by