Minimizing Chi-Squared Function in MATLAB

In summary, A user is trying to minimize a sum of squares (chi-squared) function in MATLAB, but is encountering an error when using the fminsearch function. The model includes a definite integral from zero to data values, and has three parameters that need to be minimized. The user has created a function handle and a sum of squares function, but is unsure what is causing the error. The data being used is a vector of observed values at different z values.
  • #1
aymer
16
0

Homework Statement

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.

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.

thankyou
 
Physics news on Phys.org
  • #2
Is data a structure with vectors or are they symbols? I'm guessing your problem is with your structure either way.
 
  • #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
 

1. What is the Chi-Squared Function in MATLAB?

The Chi-Squared Function in MATLAB is a statistical tool used to assess the goodness of fit between a theoretical model and observed data. It measures the difference between the expected and observed values, and a smaller value indicates a better fit between the model and the data.

2. How do I minimize the Chi-Squared Function in MATLAB?

To minimize the Chi-Squared Function in MATLAB, you can use the built-in function called "fminsearch". This function takes in the Chi-Squared Function as an input and finds the values of the parameters that minimize the function.

3. What inputs are required to use the "fminsearch" function in MATLAB?

The "fminsearch" function in MATLAB requires the Chi-Squared Function as the first input, the initial guess for the parameters as the second input, and any additional parameters needed for the function as the remaining inputs. You can also specify the maximum number of iterations and the tolerance level as optional inputs.

4. How do I interpret the results of the minimized Chi-Squared Function?

The minimized Chi-Squared Function returns the values of the parameters that provide the best fit between the model and the data. You can use these values to plot the model and compare it with the observed data. A lower Chi-Squared value indicates a better fit between the model and the data.

5. Can I use the minimized Chi-Squared Function to compare multiple models?

Yes, you can use the minimized Chi-Squared Function in MATLAB to compare multiple models. By calculating the Chi-Squared value for each model, you can determine which one provides the best fit for the observed data. However, it is important to note that the Chi-Squared Function does not consider the complexity of the model, so it should be used in conjunction with other statistical tests to make a robust comparison.

Similar threads

  • Calculus and Beyond Homework Help
Replies
3
Views
1K
  • Advanced Physics Homework Help
Replies
0
Views
246
  • Advanced Physics Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
810
  • Math POTW for Graduate Students
Replies
1
Views
973
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
848
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
772
  • Advanced Physics Homework Help
Replies
6
Views
1K
  • General Math
Replies
6
Views
787
Back
Top