Summation in function handle

조회 수: 9 (최근 30일)
jlvdoorn
jlvdoorn 2022년 6월 1일
댓글: Matt J 2022년 6월 1일
Hi,
I would like to have the following equation in a function handle (which represents a cost function in this case):
Herein, x_1 until x_4 are variables and Hp is an array containing 10 entries.
How would I implement this? I expiremented a bit but that did not work out properly.
for k=1:10
J_A = @(x) sum(abs(Hpe(k)-x(1)*exp(-1i*omega(k)*x(2))*(x(3)^2)/((1i*omega(k)^2)+2*x(3)*x(4)*1i*omega(k)+x(3)^2))^2);
end
It seems like only k=10 is taken into account this way.
Appreciate the help.

채택된 답변

Matt J
Matt J 2022년 6월 1일
J_A = @(x) sum(abs(Hpe-x(1).*exp(-1i.*omega.*x(2)).*(x(3).^2)./((1i.*omega.^2)+2.*x(3).*x(4).*1i.*omega+x(3).^2)).^2);
  댓글 수: 2
jlvdoorn
jlvdoorn 2022년 6월 1일
편집: jlvdoorn 2022년 6월 1일
Thanks,
Now how do i add a penalty (say, 10^6) to the cost function if any of the variables, x(1) to x(4) become negative?
I am using 'fminsearch' for optimizing the problem.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by