MATLAB - 使用fminsearch与基质

问题描述:

如果我有例如一个函数:MATLAB - 使用fminsearch与基质

k=1:100 
[email protected](s) sum(c(k)-exp((-z(k).^2./s))) 

其中c和z是与相同尺寸的矩阵(例如1×100),是否有任何的方式来使用fminsearch找到“s”值?

+0

这个例子中'k'是什么? – 2013-02-08 18:21:37

+0

我编辑.thanks – George 2013-02-08 18:26:48

+0

k在这里是IRRELEVANT。如果c是1x100向量,则c和c(k)是相同的。 – 2013-02-08 18:36:11

fminsearch需要在第二个参数的初始条件,没有边界条件(尽管有些选项可能支持边界)。

只需拨打

fminsearch(func,-0.5) 

哪里看到传递一个向量的例子,是在多个系数的多维搜索,而载体是每个系数的初始值。不限制搜索空间。

您还可以使用

fminbnd(func, -0.5, 1); 

执行限制最小化。

但我认为你应该尽量减少错误的规范,而不是总和(最小化总和导致大的错误幅度 - 非常非常负面)。

如果您有优化工具箱,那么lsqnonlin可能会有用。

我猜你想找到你的象征功能的argmin,使用 Index of max and min value in an array

OR

ARGMAX/ARGMIN by Marco Cococcioni

function I = argmax(X, DIM) 
%ARGMAX Argument of the maximum 
% For vectors, ARGMAX(X) is the indix of the smallest element in X. For matrices, 
% MAX(X) is a row vector containing the indices of the smallest elements from each 
% column. This function is not supported for N-D arrays with N > 2. 
% 
% It is an efficient replacement to the use of [Y,I] = MAX(X,[],DIM); 
% See ARGMAX_DEMO for a speed comparison. 
% 
% I = ARGMAX(X,DIM) operates along the dimension DIM (DIM can be 
% either 1 or 2). 
% 
% When complex, the magnitude ABS(X) is used, and the angle 
% ANGLE(X) is ignored. This function cannot handle NaN's. 
% 
% Example: 
%  clc 
%  disp('If X = [2 8 4; 7 3 9]'); 
%  disp('then argmax(X,1) should be [2 1 2]') 
%  disp('while argmax(X,2) should be [2 3]''. Now we check it:') 
%  disp(' '); 
%  X = [2 8 4; 
%   7 3 9] 
%  argmax(X,1) 
%  argmax(X,2) 
% 
% See also ARGMIN, ARGMAXMIN_MEX, ARGMAX_DEMO, MIN, MAX, MEDIAN, MEAN, SORT. 

% Copyright Marco Cococcioni, 2009. 
% $Revision: 1.0 $ $Date: 2009/02/16 19:24:01$ 

if nargin < 2, 
    DIM = 1; 
end 

if length(size(X)) > 2, 
    error('Function not provided for N-D arrays when N > 2.'); 
end 

if (DIM ~=1 && DIM ~= 2), 
    error('DIM has to be either 1 or 2'); 
end 

if any(isnan(X(:))), 
    error('Cannot handle NaN''s.');  
end 

if not(isreal(X)), 
    X = abs(X); 
end 

max_NOT_MIN = 1; % computes argmax 
I = argmaxmin_mex(X, DIM, max_NOT_MIN);