problem using fminsearch, as parameters that I want to optimize is not input for the handle function

2 views (last 30 days)
What if my model is composited by many subfunctions, and the handle function I am going to use in fminsearch doesn't include the parameters I want to optimize?
For example:
handle function is RMSD(prediction, experiment)
but the parameters I want to optimize is lambda1 and lambda2 which is in the mainfunction where RMSD is called?
How should I write the fminsearch then?
so far i write
[optimal,rmsdmin,exitflag,optimaloutput]=fminsearch(RMSD,@mainfunction,optimal0);
doesn't work

Answers (2)

Yogananda Jeppu
Yogananda Jeppu on 11 Nov 2017
I am not sure how to do this. I have been using global in my function and optimizing using fminsearch (fmins before). It always works for me - though not a very elegant solution. My take has been I want the optimized solution not the code!

Alan Weiss
Alan Weiss on 13 Nov 2017
This is a question of thinking deliberately. If I understand you correctly, you want to find the control variable lambda = (lambda(1),lambda(2)) that gives the lowest value of RMSD. But RMSD does not depend explicitly on lambda.
Here is where deliberate thinking comes in. fminsearch wants a function that accepts lambda and gives the value of RMSD. If you think about it, you should realize that is exactly what you want, too: the value of RMSD for a given value of lambda. Either you can compute these values or you cannot. If you can compute them, then think about how you do it, and write a MATLAB function that takes a value lambda and returns the RMSD value (this function may well call RMSD).
For examples that use extra parameters (this may help), see Passing Extra Parameters.
Alan Weiss
MATLAB mathematical toolbox documentation

Categories

Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!