fminbnd Error using .^ Matrix dimensions must agree.

I'm trying to use fminbnd to find a scalar k that minimizes the difference between three sets of values, but receive the above error.
My Function:
function[f] = min_diff(k,sample1,sample2,sample3)
alpha1 = 5 ./ (sample1 .^ k);
alpha2 = 7 ./ (sample2 .^ k);
alpha3 = 10 ./ (sample3 .^ k);
mean1 = mean(alpha1);
mean2 = mean(alpha2);
mean3 = mean(alpha3);
f = abs(mean1-mean2) + abs(mean1-mean3) + abs(mean2-mean3);
Code to run function:
[k_estimate,fval,exitflag] = fminbnd(@(k) min_diff(k,sample1,sample2,sample3),0,[],options);
Full Error Message:
Error using .^
Matrix dimensions must agree.
Error in min_diff (line 3)
alpha1 = 5 ./ (sample1 .^ k);
Error in @(k)min_diff(k,sample1,sample2,sample3)
Error in fminbnd (line 214)
x= xf; fx = funfcn(x,varargin{:});
I'm using dot-operators everywhere. Does this have something to do with how fminbnd runs?

1 件のコメント

James Tursa
James Tursa 2015 年 11 月 16 日
What are the sizes of the variables involved?

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2015 年 11 月 16 日

0 投票

You are trying to use fminbnd with [] as your x2. That is giving you an empty k.
If you want 0 to be the lower bound and you do not want an upper bound then use inf for the upper bound.

1 件のコメント

Priyanka Thatipamala
Priyanka Thatipamala 2015 年 11 月 16 日
Indeed, it was that simple. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOptimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by