MATLAB: Curve fitting one portion of the data

curve fitting

Hello,
I have a data of which one portion is linear and the other portion is a discontinuous curve of the form y=a*exp(-b*kt). How do I only fit the curve portion of the data. I am new to Matlab. Thanks.

Best Answer

The goal is to remove the linear part so you need to find when the linear part ends and the curvilinear part begins.
There are lots of ways to do that.
You could try matlab's ischange() function depending on how abrupt the change is.
If the linear part is truly linear, you could fit it to a line using just the first few indicies that you're sure are linear and then compute the residuals between the linear fit and the entire curve to detect when the deviations grow beyond the noise level.
A simple differentiation (diff(), gradient()) would show a spike when the curve begins, depending on the abruptness.
Think about it from a mathematical perspective before you start worrying about code. Once you have the index value of where the curve begins then you just need to isolate the nonlinear part and fit it with your equation.