Using fminunc with blackbox

조회 수: 6 (최근 30일)
jeff
jeff 2016년 3월 23일
답변: sanya gode 2019년 10월 29일
A blackbox code (obj_b3.p) defines a function that takes a vector of length 2 and returns some value based on that function. I want to find the global minimizer, and instead of guess and check I want to use fminunc (have never used before, have looked at doc and help and tried googling examples but they all have known functions that they make anonymous). To do this I intend on using a lot of x0 (guess) values.
how do i set up the basic code?
what I've tried:
v = [1;1] % creates a vector of length 2 (blackbox code won't accept a 1,2, only a 2,1)
x0=[0;0]; % Initial guess for fminunc
v = fminunc(obj_b3,x0)
matlab returns that there aren't enough inputs.
Can someone post a simple example of how to do this using a blackbox.m file (hope its obvious that the blackbox.p file does not allow one to actually see the code to evaluate).
Thanks!

채택된 답변

Alan Weiss
Alan Weiss 2016년 3월 23일
fun = @obj_b3;
x0 = [0;0];
x = fminunc(fun,x0)
You might want to consult the documentation on optimizing a simulation or ODE in case your black-box function does not distinguish between nearby values very well.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 2
jeff
jeff 2016년 3월 23일
I actually just used x = fminunc(@obj_b3,x) (thats without the options), but your answer is exactly the same idea. Can you explain why the @ symbol is necessary in matlab? I have seen minimal documentation on it and it just eludes me.
Alan Weiss
Alan Weiss 2016년 3월 23일
You should read about function handles.
The point is, how can you tell MATLAB to work with a function? I mean, you want to take a function ( fminsearch ) that operates on another function (your objective). So how should you pass the objective? The answer is with a handle to the objective.
Alan Weiss
MATLAB mathematical toolbox documentation

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

추가 답변 (1개)

sanya gode
sanya gode 2019년 10월 29일
Hello,
I am working on Equivalent Circuit Modeling for estimating the battery parametrs. I read in MAthworks documentation that the model can be Blackboxed for sharing with certain customers so that they can modeify it accourding o the application for which they are using the battery without knowing the internal parameters. I read that once the model is created we need to generate the code and than we have create a new simulink model based on the generated code.
Can you please elaborate on how exactly do we need to blackbox the model based on the generated code ?
Your answers will be very helpful and appreciated.
Thanks in advance.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by