function with myblackbox using fminunc
Show older comments
Hello guys! I got a Function F(y(x)) = sum (( yref-y(x))^2) and x(1) = q and x(2)=r and x=[q;r] and yref=0. I wanted to code this function to be used in a multi-objective optimization etc.
my initial idea is:
function F = myblackbox(x)
q = x(1)
r = x(2);
yref = 0;
y = solvemyoptimizationproblem(q,r);
F = somefunctionofy(y);
but i don't know how to use fminunc here to do a blackbox optimization and how to replace those things to have F(y(x)) correctly.
Answers (1)
lsqnonlin would be better suited to this,
x0=[q_guess,r_guess];
x=lsqnonlin( @(x) yfunction(x(1),x(2))-yref, x0);
11 Comments
Ali Esmaeilpour
on 30 Aug 2019
Matt J
on 30 Aug 2019
The code is as complete as your description allows. In your problem statement
F(y(x)) = sum (( yref-y(x))^2)
You haven't told us what y(x) looks like.
Ali Esmaeilpour
on 30 Aug 2019
Ali Esmaeilpour
on 30 Aug 2019
Ali Esmaeilpour
on 30 Aug 2019
Ali Esmaeilpour
on 30 Aug 2019
Ali Esmaeilpour
on 30 Aug 2019
how can I find a function for my closed-loop response y?
To use lsqnonlin or any other Matlab optimizer, all you need is code that generates y for a given choice of [x(1), x(2)], which you seem to have already. For lsqnonlin, you also need this function to be differentiable, and it is not clear from the complexity of your code if that is the case.
SInce we are not sure it is differentiable, then you could use fminsearch instead, which doesn't use derivatives, and works well for a small number of unknowns,
x=fminsearch(@(x) norm(yfunction(x)-yref), [q_guess, r_guess])
Ali Esmaeilpour
on 30 Aug 2019
Matt J
on 30 Aug 2019
fminsearch will search for the optimal x. You put it wherever you need the optimization to occur.
Categories
Find more on Problem-Based Optimization Setup in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!