fminbnd loop leads to same optimizer

1 view (last 30 days)
I have a matrix of parameter A that is 2*2 matrix and other matrix B. The solution matrix C that is 2*1
Then I run
for i=1:1:2
C(i,1)=fminbnd(@(b) fun(A(i,1),A(i,2),b,B),0,1)
end
Then strangely, even when paramters A(1,:) and A(2,:) are very different, I got the same optimizer. For example, A is
0.870639815937867 0.845094090200317
0.748241117938819 0.400000548158531
C is
0.150263993746969
0.150256643269687
This happens multiple times. What is going on? Can it be that first run of fminbnd affects the second run of fminbnd?
  4 Comments
John D'Errico
John D'Errico on 3 Aug 2020
The crystal ball is so foggy today. It simply will not show me the contents of your computer, to tell us what the function fun does. It just keeps on telling me that you will soon come into a large sum of money. Or maybe that means I will come into some money. Whatever. ONE of us will be getting righ soon. Maybe. Should I try my deck of MATLAB tarot cards instead? Tea leaves? :)
If you really want help, then you need to show us the function fun.
alpedhuez
alpedhuez on 3 Aug 2020
Yes you wrote fminsearchbnd so I will appreciate if you take a look at the attached mix file. If one run this script for, let me say, 15 times, then one will encounter a case where the solutions of the optimization problems are the same even though the paramters are different. I wlll appreciate comments.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 3 Aug 2020
Edited: Matt J on 3 Aug 2020
In addition to hwat John said, you could plot the function to confirm whether fminbnd is giving you a good approximation of the minimizer in each case. If it is, that will tell you that it is not fminbnd's fault. The minimizer is simply not as sensitive a function of A as you had believed.
I would note that there is clearly some impact that A is having on the output. The successive C(i) that you have showed are similar, but not identical.
  15 Comments
Matt J
Matt J on 4 Aug 2020
If the break point is not reached, it may be because an if-else-end statement sent the code along a different path...

Sign in to comment.

More Answers (0)

Categories

Find more on Operating on Diagonal Matrices 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!