Minimizing Chi-Squared Function in MATLAB

Click For Summary
SUMMARY

The forum discussion focuses on minimizing a chi-squared function in MATLAB using the fminsearch function. The user constructs a model function handle, modelfun1, to integrate a specific equation involving parameters a and b, and subsequently defines a sum of squares function, sum1. An error arises during the minimization process, indicating insufficient input arguments for the function. The issue is identified as a potential problem with the structure of the data being passed to the function.

PREREQUISITES
  • Understanding of MATLAB function handles
  • Familiarity with chi-squared minimization techniques
  • Knowledge of numerical integration in MATLAB
  • Experience with MATLAB data structures, specifically vectors
NEXT STEPS
  • Review MATLAB documentation on function handles and variable input arguments
  • Learn about MATLAB's fminsearch function and its requirements
  • Explore numerical integration techniques in MATLAB, particularly using the int function
  • Investigate how to structure data in MATLAB for optimization functions
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those involved in statistical modeling, data analysis, and optimization tasks. It is especially relevant for students and professionals working with chi-squared functions and numerical methods.

aymer
Messages
16
Reaction score
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
Is data a structure with vectors or are they symbols? I'm guessing your problem is with your structure either way.
 
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
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
0
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K