I have several large data sets which follow the following pattern: A position is measured, a force is applied until a new equilibrium is found.
I'd like to find a fit for the position, at least at the plateaus, and preferably of the inter lying section, which in this case approaches a line.
I tried fitting the data with Clip
, and with Piecewise
.
nlm = NonlinearModelFit[v40s1000h,Piecewise[{{a, x < A}, {b, x > B}}], {a, b, A, B, c, d}, x]
This creates a decent fit only if I specify the values for A and B, but then I have to estimate those values for each data set manually. It also doesn't really work to just add NMinimize
, or add the piecewise part for the middle bit.
Is There anything else I can try?
http://s000.tinyupload.com/?file_id=35616536027018518052 << file
v40s1000h
. An idea would be to create the first few terms of a Fourier expansion and fit that within the domain of interest. $\endgroup$NonlinearModelFit
works my minimizing some cost function (e.g. total squared error), but the cost function can't be evaluated if your piecewise function doesn't return a value for some values of x. Have you tried using something like{(a+b)/2,A<x<B}
as a fallback? Alternatively, you could come up with your own cost function and just optimize that. $\endgroup$