Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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).

Risposta accettata

Roger Wohlwend
Roger Wohlwend il 4 Set 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 Commento
Shawn
Shawn il 23 Set 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by