Fitting a function of the form x-a for unknown a

1 次查看(过去 30 天)
We have data which is roughly exponential for x<a, and approximately a power law (x-a)^b for x>a, but I'm unclear how (or if it's even possible) to find a adaptively.
Clearly fitting a function of the form Ce^(bx)+ c(x-a)^d is a problem (if for no other reason than the fact that 0<x<a gives complex value), but short of brute force trial and error to find a, I'm not quite sure where to start.
I guess I'm looking to optimize the value of a by simultaneously fitting the exponential below and the power law above until both converge (though I'm pretty sure that's not possible without a fair amount of work).

采纳的回答

Roger Wohlwend
Roger Wohlwend 2014-9-4
Yes, you're looking for an optimization, and I can assure you that it is not a fair amount of work. However it won't work with the function you mention in your question. Instead use the optimization function lsqcurvefit with the following function you want to fit:
function y = myoptfunc(coeff, xdata)
y = NaN(length(xdata),1);
q = xdata < coeff(1);
y(q) = coeff(2) * exp(coeff(3) * xdata(q));
y(~q) = coeff(4) * (xdata(~q) - coeff(1)).^coeff(5);
end
The vector coeff contains your coefficients. The first one is your parameter a.
  1 个评论
Shawn
Shawn 2014-9-23
Cheers, thanks. Sorry for the delay in getting back to this, life intervened! I'll have a play with the method you suggested and see how it goes, it looks generally useful for us for some other types of fitting we need to do as well.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by