MATLAB >> fminsearch with three parameters

by Bob Garrett » Thu, 20 Jan 2011 05:14:05 GMT

I'm trying to do an fminsearch on a function with three free variables and I get the following message :
??? Attempted to access p(3); index out of bounds because numel(p)=2.

Error in ==> @(p)lorfit(Table1,p(1),p(2),p(3))


Error in ==> fminsearch at 205
fv(:,1) = funfcn(x,varargin{:});

here's the code for my function lorfit :
function [ ansa ] = lorfit(x,G,x0,H)
ansa = 0;
for c = 1:length(x)
ansa = ansa + (x(c,2) - (H/(2*((x(c,1)-x0)^2+(G/2)^2))))^2;
end
ansa = sqrt(ansa);

end

Can someone tell me what I'm doing wrong?

MATLAB >> fminsearch with three parameters

by Peter Perkins » Thu, 20 Jan 2011 22:26:36 GMT



Whatever code is calling FMINSEARCH is apparently calling it with a
starting vector that has fewer than three elements. Set a breakpoint at
that line of code, run it, and see what's being passed in.

Hope this helps.

Similar Threads

1. fminsearch with three parameters

I'm trying to do an fminsearch on a function with three free variables and I get the following message :
??? Attempted to access p(3); index out of bounds because numel(p)=2.

Error in ==> @(p)lorfit(Table1,p(1),p(2),p(3))


Error in ==> fminsearch at 205
fv(:,1) = funfcn(x,varargin{:});

here's the code for my function lorfit :
function [ ansa ] = lorfit(x,G,x0,H)
ansa = 0;
for c = 1:length(x)
ansa = ansa + (x(c,2) - (H/(2*((x(c,1)-x0)^2+(G/2)^2))))^2;
end
ansa = sqrt(ansa);

end

Can someone tell me what I'm doing wrong?

2. "special" to fit a three-parameter function - MATLAB

3. weibull three parameters

Hi,

I would like to adjust a series of extremal data to the weibull of three parameters function of which its CDF reads:

F(x) = 1-exp(-(x-gamma/beta)^alpha)

how can I obtain the values of these parameters for my data?

I was looking for this function in Matlab, but I think it is not supported by the statistics toolbox (it only appears weibull of two parameters)

Any help is appreciated. Thanks in advance!

4. three-parameter distribution - MATLAB

5. Fitting a model to three parameters with data point repetitions

Hello,

I have three parameters, abbreviated by c, m, p. The dataset i have has four columns:

index
c
m
p

Index is just a uniquely identifier for each row. There are 3167 rows in the data.

I intuitively can say that the parameters c, m, p are have a correlation. However, what I can definitely say is that p>m for each row.

What I need to do is to fit a model to these parameters so that I can correlate them in one equation. Instead of fitting a model for three parameters, I tried to fit a model to C(3,2)=3 pairs of these paramaters: (c,m), (c,p), (m,p). So I drew their scatterplots and started fitting, with various methods.

The challenge here is that for each of these three scatterplots, there are multiple y values for one x value. So if we are to fit a function to any of the scatterplots, f(x) will give a single y value, whereas the data has multiple y values.

I used splines, smoothing, regression... and such. The fitting is clearly not good. Moreover, I cannot get the equation of the model that I fit using these methods, I just plot the fitting function (which is actually, just visually, not a good fit) and don't even know the the form of the function itself at all.

What else can I do to find a correlation among these three parameters? Can I have a good fit and can I know the function of the fit at the same time? Is there a better approach to fit a model to three parameters, where some of the data are repeated?

Thanks.

6. Fminsearch over 20 parameters - MATLAB

7. fminsearch mle parameters

hello,

I am trying to use fminsearch to solve for the paramter phee. Whenever
I type:
phiHat = fminsearch(exact(z,x),z,x);

I get the error message:

??? Error using ==> fcnchk at 105
FUN must be a function, a valid string expression,
or an inline function object.

Error in ==> fminsearch at 178
funfcn = fcnchk(funfcn,length(varargin));

my function is defined as:
function result = exact( h,q)


% Estimation
% =============
x       = q(:); % should be column vectors !
z       =h(:);
phee     = (inv(x'*x))*(x'*z);
N       = length(x);
sig2    = (z-phee*x)'*(z-phee*x)/N;
w      = (N/2/log(2*pi))+(N/2)*log(sig2)+((z-phee*x)'*(z-phee*x))/
2*sig2;
result = struct( 'phee',phee);
end

I have no idea what I am doing wrong, any help would be welcome!

-Nora

8. Breaking out of fminsearch given a parameter - MATLAB