Fitting a complicated function

5 次查看(过去 30 天)
Marcel
Marcel 2012-6-19
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?

回答(1 个)

the cyclist
the cyclist 2012-6-20
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 个评论
Walter Roberson
Walter Roberson 2012-7-9
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 2012-7-9
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Least Squares 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by