# help with fminsearch output value

4 views (last 30 days)
ARP on 25 Jul 2017
Commented: ARP on 25 Jul 2017
Hi all,
I'm trying to understand the use of fminsearch, to find the argument that minimizes the difference between two data sets (one experimental and several theoretical ones). As described in some articles, the mathematical expression is : min(mean(Xi-X_av).^2), were Xi = Experimental/theory(n) and X_av is the average off all the Xi.
As a test, I created a simple function as the experimental (EXP) and theory (Xi).
a = [1:10]';
EXP = exp(a*0.2);
coeff = [0.1,0.13,0.15,0.17,0.2];
theo = exp(a.*coeff)
Xi = EXP./(theo);
It can be seen that (a) are the row numbers. There are 5 arrays corresponding to the different functions. Xi(:,5) should be the answer to fminsearch.
Continuing with the function to minimize the squared difference,
X_av = mean(Xi,2);
fun = @(Xi)(mean(Xi-X_av).^2);
[x,val] = fminsearch(fun,1);
and turns out that val = 1.637758538081846e-09, instead of 5. X = 1.363769531250001.
I have been reading the reference page for fminsearch, but I am bit stacked.
In practice, I will have an array of values as a look up table, that need to be compared to the experimental data. Rows are not important (will be the frequency). What I need is the column number that gives the lowest difference. The data is non-linear by the way, typically as 10log10.
- To make fminsearch as a function of columns, is @(Xi) correct?. - As in my case, how to set up initial x0 values in [x,val]?. Using value from 1 to 8, val output does not change. - X shouldn't be 0 since it's the best solution?
Thanks

John D'Errico on 25 Jul 2017
A column number is a discrete thing. fminsearch cannot solve that.
Regardless, you don't want to use an optimization (minimization) tool, but more like a root finder, if you are searching for a column of an array. Again, that is not fminsearch.
Just use a loop. Test each column. Take the best. You don't have many columns, so WTP?

#### 1 Comment

ARP on 25 Jul 2017
Thanks for the reply. This was just a representative example of what I will be doing. I will be working with hundreds of columns later on. Each column that I call theory is the solution to a code. This in the context of ultrasound. Each theory column represents a different form function defined by a parameter. I though I could simplify the problem looking in columns. Once I find which one has the minimum difference, I can extract the respective constant.
thanks anyway