1

I am trying to calculate the minimum of a function with multiple variables, the only constraints I have are the upper and lower bounds of the variables. The problem I am having is that fmincon does not change the input value from the initial guess value I give it.

This is the output I get:

initGuess = 0.6159
x = 0.6159

Initial point is a local minimum that satisfies the constraints.

Optimization completed because at the initial point, the objective function is non-decreasing in feasible directions to within the selected value of the function tolerance, and constraints are satisfied to within the selected value of the constraint tolerance.

<stopping criteria details>

This is my call to fmincon:
A = [];
b = [];
Aeq = [];
beq = [];
lb = 0;
ub = 1;
initGuess = 0.6159;
options = optimset('TolX',1e-12,'TolCon',1e-12,'TolFun',1e-12,'Algorithm','interior-point');
[optAM,optBC] = fmincon(@(x) cmpBC(x,epochDate,epochDate2,root,rvfm),[initGuess],A,b,Aeq,beq,lb,ub,nonlcon,options);

I tried multiple initial guesses and the same thing happens, please help not sure how fix this.

EDIT****

cmpBC:
function output = cmpBC(x,epochDate,epochDate2,root,rvfm)

cmdParamString = ['HPOP */Satellite/COMDEV_Sat Drag On 2.2 ' num2str(x(1)) ' "NRLMSISE 2000" File "C:\Program Files (x86)\AGI\STK 10\Data\sw20100101.txt"'];

root.ExecuteCommand(cmdParamString);


cmd = horzcat('Propagate */Satellite/COMDEV_Sat', ' "', epochDate, '" "', epochDate2,'"');
root.ExecuteCommand(cmd);
cmd = 'Report_RM */Satellite/COMDEV_Sat Style "J2000 Position Velocity"';
variableB = root.ExecuteCommand(cmd);
theSize = variableB.count;
posArray2=variableB.Item(theSize-2);

C = strread(posArray2,'%s','delimiter',',');


output = norm([str2num(C{2})-rvfm(1) str2num(C{3})-rvfm(2) str2num(C{4})-rvfm(3)]);
%rvfm is the known position of the satellite
end
Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
  • So if your initial guess so happens to be a local minimum of the objective function, then what exactly is your problem? The function behaves exactly as it should - it converges when it reaches a local minimum... which so happens to be your first guess. Do you want to find the **global** minimum instead? – rayryeng Sep 02 '15 at 20:19
  • No matter what my initial guess is, it doesn't change. – user3897744 Sep 02 '15 at 20:20
  • Then it's a problem with your cost function. The code you provided is basic boiler-plate code for trying to optimize an objective function. I can't tell you what's wrong with it unless you describe or show us what `cmpBC` is. There's no insight or help I can provide without it. If you can't show us what `cmpBC` is, then at least **describe** what the cost function is. By describing it, we may be able to pinpoint what exactly is wrong... but the actual code would be awesome too. – rayryeng Sep 02 '15 at 20:21
  • cmpBC pretty much uses the input x (drag coefficient) to calculate the position of a satellite. I want to minimize the error between know position of satellite and calculated position (output). So I want to find the corresponding drag coefficient for the minimal error. Is there a way to make fmincon find the global minimum, that may solve it if all my initial guesses are local minimums? – user3897744 Sep 02 '15 at 20:25
  • How do you calculate this error? Remember, I can't help you figure it out unless I know what `cmpBC` is doing. It's at the point now where I really need to see some code. If you don't, then I (nor anyone else) can help you solve your problem, and unfortunately our conversation will have to stop here. – rayryeng Sep 02 '15 at 20:26
  • Okay, I have added it – user3897744 Sep 02 '15 at 20:31
  • Cheers. Can you explain to me what's going on in `cmdParamString`? Are you calling some sort of data acquisition program that requires `x` - which is your guess at a current iteration? – rayryeng Sep 02 '15 at 20:35
  • I honestly don't know what's going on in `cmpBC`, but did you try displaying what each variable contains at a particular iteration in `fmincon`? Do the command strings you enter in agree with what you should put in given `x`? – rayryeng Sep 02 '15 at 20:40
  • 1
    Given that your cost function is a function of one variable that goes between finite lb and ub, I'd recommend plotting it over a grid of points, i.e. `x=0:0.001:1;plot(x,costfcn(x))` to see what the cost looks like. For debugging purposes, that'll give you an idea of why the optimization thinks all points are a minima. – Phil Goddard Sep 02 '15 at 20:43
  • Yea i tried displaying x at each iteration and it doesnt change. It is always initial guess value. The cmd param string is all fine – user3897744 Sep 02 '15 at 20:43
  • @PhilGoddard - That's a good tip Phil! – rayryeng Sep 02 '15 at 21:01
  • 1
    @user3897744: I'm not suggesting plotting x at each iteration. I'm suggesting plotting the cost as a function of x. – Phil Goddard Sep 02 '15 at 21:09
  • Plotting it doesnt work since x never changes, the function is always trying the same value. I am not understanding what you mean Phil, doesn't x have to change for me to get a meaningful plot? – user3897744 Sep 02 '15 at 21:13
  • @user3897744: Yes. You need to define `x` and how it ranges to plot `costfcn`. This is why @PhilGoddard defined `x=0:0.001:1`, for example. In your case `costfcn= @(x)cmpBC(x,epochDate,epochDate2,root,rvfm)`. – horchler Sep 02 '15 at 21:19
  • Nevermind, i misunderstood. – user3897744 Sep 02 '15 at 21:21

0 Answers0