在Matlab中使用fminbnd函数时由于下限和上限引起的意外错误

时间:2012-11-20 02:33:40

标签: matlab optimization constraints limit runtime-error

我根据系数的合法域值在fminbnd函数中使用下限和上限,如下所示:

[x,fval,exitflag] = fminbnd(@(x) minimize_me(sill, x(1), x(2), x(3), cov), [x1l x2l x3l], [x1u x2u x3u], opts);

[x1l x2l x3l][x1u x2u x3u]是表示优化系数的下限和上限的向量。我的问题的范围如下:

0<=x1l<=5
0<=x1u<=5

0<=x2l<=5
0<=x2u<=5

0<=x3l<=180
0<=x3u<=180

奇怪的问题是,即使在我的域中选择某些值,我也会收到如下所示的错误:

??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> fminbnd at 271
    x = xf + si * max( abs(d), tol1 );

例如,如果我选择,我会收到错误:

[x1l x2l x3l], [x1u x2u x3u] = [0 0 0], [5 5 180][x1l x2l x3l], [x1u x2u x3u] = [1 1 0], [5 5 180][x1l x2l x3l], [x1u x2u x3u] = [1 2 0], [5 5 180]等。

但是,如果我选择[x1l x2l x3l], [x1u x2u x3u] = [5 5 0], [5 5 180][x1l x2l x3l], [x1u x2u x3u] = [3 0 0], [3 5 180]等,我不会收到错误。

1 个答案:

答案 0 :(得分:4)

根据documentationfminbnd仅适用于将单个标量作为参数的函数。

在文件交换中查看fminsearchbnd

http://www.mathworks.com/matlabcentral/fileexchange/8277-fminsearchbnd