Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How can I pass a function into a function and find the minimum?

조회 수: 1 (최근 30일)
Dimitra Kyriakouli
Dimitra Kyriakouli 2019년 12월 2일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi! I have a problem when trying to minimize a function with fminsearch. I have this function:
function [f] = myfunc(X)
x1 = X(1);
x2 = X(2);
f = 2*x1^2 + 2*x1*x2 + 2*x2^2 - 6*x1;
end
and I want to minimize the f(X+a*grad) where X and grad are known.
I tried this:
[f] = myfunc(@(a) X + a * grad);
a = fminsearch(f,0)
but it doesn't seem to work.
Do you have any suggestions on how to make my code work?
  댓글 수: 1
Star Strider
Star Strider 2019년 12월 2일
Please describe what you want to do.
the ‘f’ assignment and your fminsearch call make no sense.

답변 (1개)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 12월 2일
solution:
f=@(a) myfunc(X + a * grad);
a = fminsearch(f,0)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by