Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
Dimitra Kyriakouli
Dimitra Kyriakouli am 2 Dez. 2019
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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 Kommentar
Star Strider
Star Strider am 2 Dez. 2019
Please describe what you want to do.
the ‘f’ assignment and your fminsearch call make no sense.

Antworten (1)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH am 2 Dez. 2019
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