fminsearch with three parameters

  • Permalink
  • submit to reddit
  • Email
  • Follow


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?
0
Reply Bob 1/19/2011 9:14:05 PM

See related articles to this posting


On 1/19/2011 4:14 PM, Bob Garrett wrote:
> 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))

> Can someone tell me what I'm doing wrong?

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.
0
Reply Peter 1/20/2011 2:26:36 PM
comp.soft-sys.matlab 203507 articles. 529 followers. Post

1 Replies
494 Views

Similar Articles

[PageSpeed] 48


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

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! rodrikas <carballo.rodrigo@gmail.com> wrote in message <1429959987.60090.1291591329863.JavaMail.root@gallium.mathforum.org>... > Hi, > > I would like t...

multiple parameter fminsearch
I have a question regarding runnign fminsearch with multiple parameters that are vectors themselves: theta etta lambda and gamma I define a function m2 as: function [min]=m2(theta, etta, lambda, gamma) but then when I call it: [theta, etta, lambda, gamma]=fminsearch(@m2,[theta0;etta0;lambda0;gamma0],opts); it gives me an error message saying that "Input argument 'theta' is undefined." am I misspecifying the fminsearch? thanks, olga olga gorbachev wrote: > > > I have a question regarding runnign fminsearch with multiple > parameters that are vectors themsel...

Fminsearch with 7 parameters
Dear all, I am using fminsearch to minimize a function with 7 parameters..the function is very long. Fminsearch doesnt converge, each time it iterates the value of the function doesnt change (it doesnt minimize). Any ideas where the problem is? Thanks a lot Saad "Saad " <saad.badaoui07@imperial.ac.uk> wrote in message news:j1ds5v$45a$1@newscl01ah.mathworks.com... > Dear all, > > I am using fminsearch to minimize a function with 7 parameters..the > function is very long. Fminsearch doesnt converge, each time it iterates > the value of the functi...

ParametricPlot3D with three parameters
Clear[t,ph]; R=1; ph = Pi/8 ; line=R{Cos[ph]Cos[t], Cos[ph]Sin[t] ,Sin[ph]}; Lati=ParametricPlot3D[line,{t,0,Pi}] surf=Table[R{Cos[ph]Cos[t], Cos[ph]Sin[t] ,Sin[ph]}, {ph,0,1.3,.12},{t, 0,Pi,Pi/16.}]; Needs["Graphics`Graphics3D`"]; sph=ListSurfacePlot3D[surf] Show[{Lati,sph},PlotRange->All] hypsurf=Table[R{ Cos[ph]Cos[t], Cos[ph]Sin[t] ,Sin[ph]}, {ph, 0,1.3,.12},{t,0,Pi,Pi/16.},{R,1,1.15,0.05}] ; hy=ListSurfacePlot3D[hypsurf] Show[{Lati,sph,hy},PlotRange->All] " The ParametricPlot3D accepts coords in 3 D by one set of independent parameters to form lines in ...

three-parameter distribution
Hi! MatLAb gives a possibility to create own distributions to fit later in dfittool. I tried to create a three-parameter Weibull distribution and found that MatLab works only with two-parameter distributions. Of course, i can fit it as a function, but this is a nasty business. Was anyone successful to create own three- or more parameter distributions and then to fit it in the dfittool? Could you please list here the m-file? Best, Serg > MatLAb gives a possibility to create own distributions to fit later in > dfittool. I tried to create a three-parameter Weibull distribution and > f...

Confirming parameters of FMINSEARCH
Hello, I'm trying to confirm the parameters used in the FMINSEARCH function for the Nelder-Mead method nonlinear optimization (direct search) method to ensure that the necessary parameters are implemented for the convergence of my problem. I've tried looking through FMINSEARCH, OPTIMSET and OPTIMGET but haven't gotten anywhere. As I'm not specifying any options, is there somewhere I can check the default parameters? A Nelder-Mead method has four parameters: coefficients of reflection (rho), expansion (chi), contraction (gamma) and shrinkage (sigma). Any guidance would be ...

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)...

fminsearch with array of parameters
i have a matrix that may be as large as 2000 x 2000, the elements of which are parameters i want to use in fminsearch. instead of running a loop, is there a way i can calculate the optimum value by passing the array to fminsearch? gautam. On Aug 7, 11:26 pm, Gautam Sethi <gautamse...@gmail.com> wrote: > i have a matrix that may be as large as 2000 x 2000, the elements of > which are parameters i want to use in fminsearch. instead of running a > loop, is there a way i can calculate the optimum value by passing the > array to fminsearch? > > gautam. since no one has r...

Fminsearch over 20 parameters
I am searching over 20 parameters to minimize a non-linear function that is quite costly to evaluate (about 30-90 secnds per evaluation). I find that Fminsearch is behaving obstinately local, searching within fairly small neighborhoods of the initial parameters. How can I get it to take a more aggressive approach to searching the parameter space? Is there a different algorithm I can use to generate initial guesses for Fminsearch ? "John" <j.a.knowles@soton.ac.uk.removethis> wrote in message <gen6sn$dgt$1@fred.mathworks.com>... > I am searching over 20 parameters to m...

fminsearch on multiple parameters
Hey guys, So basically, I have a function that will calculate the euclidean norm between two curves, (once theoretical and another experimental) and will minimize it by altering one parameter of my theoretical curve using fminsearch. The problem is that my theoretical function does not depend on one variable, it's more like four or five of them. I have attempted to pass a vector into fminsearch, and my program runs through the loop I have made multiple times, but it is not changing the parameters at all, so it will run and then return the exact same parameters as my initial guess. Her...

Fitting with three parameters ???
Hello, I have two columns of data, say variables X and Y. Now I want to fit the da= ta with a function Y =3D x1 - x2 * exp(-x3 * X). I do not know what the val= ues of x1, x2 and x3.=20 Can anyone say if there is automatic way in IDL to define our fitting funct= ion and then obtain the fitted parameters to the data? How is non-linear fi= tting done in IDL? Also, I would like to know which function will be able t= o give me R2 correlation coefficient?=20 Thanks in advance, Madhavan Hi, You should take a look at Craig's MPFIT routines: http://cow.physics.wisc.edu/~craigm...

Initial parameters to fminsearch function
Hi, I've been using fminsearch to optimize 5 parameters for an error function. Three of the input parameters are used as coefficients so their initial value is set to 1. The other 2 parameters are more like an offset to other variables so I use the initial value of 0 so my function call looks like this: OptArg=optimset('MaxFunEvals',10000,'MaxIter',10000,'TolX',1e-6,'TolFun',1e-6); x0 = [1, 1, 1, 0, 0]; [x,MSE]=fminsearch(@pmodel_err,x0,OptArg); where pmodel_err is my error function. If I use a non zero inisial step such as: x0 = [1, 1, 1, 10, 5]; I ge...

estimation parameter using fminsearch
Hello, ....i am puzzled. My problem is to work out the parameter estimation of my model. I have 6 parameters. My objective function is too long to put in here. the aim is to get the minimum of the sum of square error SSE value. when i run using fminsearch algorithm, i got message 'increase the MaxFunEvals'. when i increase it using 'options', still got the same message and sometimes the system asking for 'increase MaxIter'. Is it okay if i just take the estimated value, eventhough the message still appear. I am also confused, why the SSE value change everyti...

three-parameter distribution #2
Hi! MatLAb gives a possibility to create own distributions to fit later in dfittool. I tried to create a three-parameter Weibull distribution and found that MatLab works only with two-parameter distributions. Of course, i can fit it as a function, but this is a nasty business. Was anyone successful to create own three- or more parameter distributions and then to fit it in the dfittool? Could you please list here the m-file? Best, Serg ...

fminsearch mle parameters #2
Hi, i'm trying to estimate the parameters of log likelihood function by using fminsearch. i have three parameters; x(1),x(2),x(3) and the set of valid parameters for x(1)-->[0,20] , for x(2)---> [0,1000], for x(3)---> [0,5000]. i want to find the estimated parameters in this set. So i have to add some conditions to fminsearch. Namely, to discourage the algorithm from finding local minumum outside the set of valid parameters, i have to define the log likelihood to be negative infinity for values outside this set. Then i have to restart the algorithm until no improvement could be...

standard errors of fminsearch parameters
does someone know how I can get the standard errors of the parameters found by fminsearch? (i.e. not the errors of each data value compared to the calculated one but the parameters fitted to my nonlinear data) "Cecilia Persson" <cecper@passagen.se> wrote in message <fel5qr$716 $1@fred.mathworks.com>... > does someone know how I can get the standard errors of the > parameters found by fminsearch? (i.e. not the errors of > each data value compared to the calculated one but the > parameters fitted to my nonlinear data) n = 200; % n data points, in the int...

Breaking out of fminsearch given a parameter
Hi Folks, I was wondering if it is possible to break out of an optimization with fminsearch should a certain value be reached. For instance, my function has a "valid" range of [-1,0). The inputs to the function that cause the -1 are non-unique, so I would like to break out of the optimization as soon as -1 is reached. If the cost function is J, I have tried if J==1 return; end; and have that in the function that is to be optimized against. However, it just goes right on even if I hard code J to be 1 in the function. Any ideas of what I can do? Thanks for the help, Adam &quo...

fminsearch w/ parameter restrictions?
I am fitting a custom function (the ex-Wald, an exponential convolved with a Wald (inverse Gaussian)) using a call to fminsearch. There are four parameters that get passed to this function, and at least one can be fixed and the others have sensible ranges I would like to stay within (e.g., always positive). How can I have fminsearch restrict its search of the parameter space to be within bounds that I specify? Is this possible? Thanks in advance for any help you can offer. -Evan PS-- I would also like to restrict one of the parameters to be a positive integer--is that possible? Evan Palme...

fminsearch
Hello, I am using fminsearch on a R3x1 parameter vector (which needs to be || x ||=1 in the end). Is it possible to call a normalization-function in-between each iteration of fminsearch? thanks, Thomas "Thomas " <ml@tomsen.org> wrote in message <gvecv2$ft3$1@fred.mathworks.com>... > Hello, > > I am using fminsearch on a R3x1 parameter vector (which needs to be || x ||=1 in the end). Is it possible to call a normalization-function in-between each iteration of fminsearch? > > thanks, > Thomas Yes, you COULD choose to normalize the vector in your obje...

using fminsearch for many parameter solution
hello, I am trying to fit data with the function A + B./(1+exp(a_plus * temp_data)) + C./(1 + exp(c_minus + d_minus * temp_data));, where A,B,a_plus, c_minus, and d_minus are scalar constants. I am trying to model "load_data" as a function of "temp_data". Being new to MATLAB, I just modified the fitcurvedemo function from the help files to what I've copied below, and then finally called fminsearch with [estimates, model] = fitcurvedemo2(temp_data,load_data); What I obtain makes no sense...can someone please point me in the right dire...

using fminsearch for estimating 3 parameters
Since the time needed for convergence is too long, I would like to change the tolerance on X by setting TolX to a vector, say optimset('TolX', [1e-4 1e-4 1e-7]). However, it doesn't work and seems fminsearch only allows scalar for TolX. I don't want to alter the program fminsearch, is there anyway to achieve the aim? In article <ef13bdb.-1@webx.raydaftYaTP>, "John Li" <johnlilijohn@gmail.com> wrote: > Since the time needed for convergence is too long, I would like to > change the tolerance on X by setting TolX to a vector, say > optimset('T...

fminsearch giving different parameter values
Dear Matlab Users, I am new user to Matlab, so apologies in advance if my question below appears too basic to regular users. I have to eventually write and maximise a customised log likelihood function in Matlab and as a starting point, decided to learn how to do this in Matlab by coding the log-likelihood functions for the exponential model with covariates (and right censoring). To begin with, my function script is coded as below and saved in a file called expcovariate_mle.m (Admittedly, the most advanced users of Matlab will recognise that the codes below may not be the most efficient ...

Solve unknown parameters using fminsearch
Hi all, I have a set of known image data of F intensity and angle x in degrees, and have to find the 2 unknowns Y1 and Y2 as shown below. F= 2*T2*(sin(x)^2)*Y1*(cos(x)^2)+ (Y1)*(cos(x)^4) I am rather new to matlab and I was thinking of using fminsearch to work the exact value of Y1 and Y2. Is it possible and how do I go about doing that? Or is there other ways to do that because I have to process 256 by 256 pixels each to get the values of Y1 and Y2. Any help will be greatly appreciated ! :) Regards, shing "Shing" wrote in message <kbe93r$3d0$1@newscl01ah.m...

fminsearch parameter estimator Standard errors
Dear all, I am using fminsearch to find the parameters using conditional maximum likelihood. Could anyone tell how to calculate the starndard errors? Thank you all. the code is below. function [P] = JDMLS(x) load('matlab.mat') alpha =0.091814920881651; beta =0.017693868312125; sigma=0.095349058726345; lambda = length(find(x > (3*std(x)))) / 4017; P0 = [alpha,beta,sigma,5,1,lambda]; [P] = fminsearch(@(P) mrjd_like(P,x),P0,optimset('MaxFunEvals',1e12)); %%%%%%%%%%%%% Subfunction %%%%%%%%%%%%% function logL = mrjd_like(P,x); T = length(x);...