我试图用fminsearch最小化一个5变量函数。我只想最小化两个变量的函数。我试过以下几种方法,但没有运气:
func = @(x,b) myfunction( x, y, z, a, b );
fminsearch(func,[x0,b0]);NxM x是YxZ维数的矩阵,b的维数是不同的。x0和b0的启动条件相同。
我见过一些类似的问题,但我还是解决不了这个问题。
在运行脚本时,我得到了以下输出:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.发布于 2017-04-16 02:14:33
通常,函数fminsearch只允许三个输入:函数句柄、初始值向量和优化选项,比如:fminsearch(@fun,x0,options)。
幸运的是,有一个小的黑客可以做,你可以把额外的参数后的选项,如:fminsearch(@fun,[x0 b0],options,z,a,b)。
如果您没有使用任何选项,应该是这样的:fminsearch(@fun,[x0 b0],[],z,a,b)。
请记住,在函数中您应该解压变量a和b,如下所示:
function[obj]=func(x0,z,a,b)
x=x0(1)
y=x0(2)
%rest of the function
endhttps://stackoverflow.com/questions/43432968
复制相似问题