Fitting a complicated function

8 views (last 30 days)
Marcel
Marcel on 19 Jun 2012
I'm trying fit a complicated function involving an infinite sum of a hypergeometric divided by a gamma function.
it looks like this
Exp(-x/R) + Exp(-x/R)* Sum(((-.48*x^(1 - m))^n)* Hypergeom(-m*n, 1 + n - m*n, x/R)/Gamma(1 + n - m*n), {n, 1, 50})
where R and m are the parameters i'm fitting and the infinite sum is approximated to 50 terms. Is there anyway to do this in matlab? I dont have Cftool but would it be have to handle this kind of function if I were to buy it? If not are there any other suggestions?

Answers (1)

the cyclist
the cyclist on 20 Jun 2012
In principle, you could use the nlinfit() function to do this. Here is a simple example with a much simpler function:
% Here is an example of using nlinfit(). For simplicity, none of
% of the fitted parameters are actually nonlinear!
% Define the data to be fit
x=(0:1:10)'; % Explanatory variable
y = 5 + 3*x + 7*x.^2; % Response variable (if response were perfect)
y = y + 20*randn((size(x)));% Add some noise to response variable
% Define function that will be used to fit data
% (F is a vector of fitting parameters)
f = @(F,x) F(1) + F(2).*x + F(3).*x.^2;
F_fitted = nlinfit(x,y,f,[1 1 1]);
% Display fitted coefficients
disp(['F = ',num2str(F_fitted)])
% Plot the data and fit
figure(1)
plot(x,y,'*',x,f(F_fitted,x),'g');
legend('data','fit')
In practice, I am not sure that fitting 50 terms will be sensible, numerically.
  11 Comments
Walter Roberson
Walter Roberson on 9 Jul 2012
I am not familiar with non-linear fitting. Looking at the stats toolbox, it appears to me that even their most general model of nonlinear fitting does not allow for constraints; see http://www.mathworks.com/help/toolbox/stats/nonlinearmodelclass.html
I do not know what you should do to proceed.
Star Strider
Star Strider on 9 Jul 2012
One function that will let you constrain parameter estimates is ‘lsqcurvefit’. Since you have an extremely large (50-term) objective function, I suggest that you consider setting an options structure to report each iteration, at least for the first few times you run it.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!