1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Minimization in matlab

  1. Jan 22, 2012 #1
    1. The problem statement, all variables and given/known data

    I am using matlab to minimize a sum of squares (chi-squared) function. My model has a definite integral (from zero to data values).The model has three parameters w.r.t which I need to minimize.

    2. relevant equations
    *I need to integrate (1+x).^(b-a-2).* exp(-b.*x) from zero to z(i), where a and b *are parameters.
    3. The attempt at a solution

    I make a function handle
    >> modelfun1=@ (y,a,b,c) (978.4./c).*int( (1+x).^(b-a-2).* exp(-b.*x),0,y)
    and then a sum of squares function as
    >> sum1=@(a,b,c,data) sum(((data.ydata-modelfun1(data.xdata,a,b,c)).^2)./data.zdata.^2);
    where data.xdata has all the z values,data.ydata are the observed values and data.zdata are the variances.
    when I minimize this function using fminsearch
    >> [tmin,ssmin]=fminsearch(sum1,[-0.1;0.06;70],[],data)
    i get the following error

    Error using @(a,b,c,data)sum(((data.ydata-modelfun1(data.xdata,a,b,c)).^2)./data.zdata.^2)
    Not enough input arguments.

    Error in fminsearch (line 191)
    fv(:,1) = funfcn(x,varargin{:});

    can someone please point out what I am doing wrong. I have tried many more things but this seems to be the most recurring error.

  2. jcsd
  3. Jan 22, 2012 #2
    Is data a structure with vectors or are they symbols? I'm guessing your problem is with your structure either way.
  4. Jan 22, 2012 #3
    The data is a vector of observed values at different z's. All the three data vectors i.e data.xdata, data.ydata and data.zdata are 32X1 matrices
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook