Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Shawn
Shawn am 3 Sep. 2014
Kommentiert: Shawn am 23 Sep. 2014
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).

Akzeptierte Antwort

Roger Wohlwend
Roger Wohlwend am 4 Sep. 2014
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 Kommentar
Shawn
Shawn am 23 Sep. 2014
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by