How to fit negative data in curve fitting?

HEllo,
How to fit negative datas in the curve fitting toolbox? I use the exponential equation of the form (a*exp(-x/b)+c*exp(-x/d)+e*exp(-x/f)+g*exp(-x/h)) to extract the a,b,c,...,h values from the fitted curve. It works fine when I have positive values but doesn't allow to fit the curve while negative values are present. The file is attached here. Please help.

 Accepted Answer

If you have negative values of your dependent variable in your data, you need to include an offset term (I call it ‘k’ here):
(a*exp(-x/b)+c*exp(-x/d)+e*exp(-x/f)+g*exp(-x/h))+k
This allows ‘k’ to become negative to account for negative dependent variable data. Be certain that you have enough data pairs to unambiguously estimate the extra parameter.

3 Comments

Hi star Strider,
I took your suggestion in to the account and I have no words to express my gratitude towards you my dear. Because of this problem, I was planning to change the whole experimental setup and you saved my 15 days of work in my master thesis. thank you so much dear.
I want following suggestion from you now. I will be obliged if you can throw some light on it.
- I took the equation a*exp(-x/b)+c*exp(-x/d)+e*exp(-x/f)+g*exp(-x/h))+k in order to account for the negative values. Now, This curve is basically a Thermal Impedance v/s time curve for IGBT module with in total 500000 datapoints to construct the curve thereby giving sufficient precision. During the fitting, I give the following boundries for my unknowns. See attached file for this. Now the question is this.
When I zoom in to the fitted curve then at specially for first 1.5 ms the curve fitting is not very precise in that particular region otherwise it fits well to my data points. Do you have any idea about how can I tighten my boundry conditions/Iteration numbers/Tolerance so that I have sufficiently nice fitting for first 1.5 ms. The reason for this nice fitting in this region is very important for my results. Please help if you have any idea about it. I have attached fitted curve as well as zoomed area. I have also pasted below my parameters which curve fitting generated.
Result is as under:
General model: f(x) = a*exp(-x/b)+c*exp(-x/d)+e*exp(-x/f)+g*exp(-x/h)+k Coefficients (with 95% confidence bounds): a = 0.01171 (0.01134, 0.01208) b = 0.5834 (0.5711, 0.5957) c = 0.01489 (0.01484, 0.01495) d = 0.06222 (0.0618, 0.06264) e = 3.225e-005 (-0.001438, 0.001502) f = 1.827 (-48.14, 51.79) g = 0.009454 (0.007632, 0.01128) h = 3.257 (3.104, 3.41) k = -0.005822 (-0.005827, -0.005818)
Goodness of fit: SSE: 0.06853 R-square: 0.9898 Adjusted R-square: 0.9898 RMSE: 0.0003702
Thank you for your kind support.
It is my pleasure!
I doubt you can get a better fit. I would not be excessively concerned about the extremely small error in the section of your fitted curve that has the most extreme slope. Adding another exponential term is likely not going to improve the fit, since the coefficients of the third term, ‘e’ and ‘f’, are not significantly different from zero, as reflected in their 95% confidence limits that include zero, so you could discard one term and not noticeably affect the fit.
You could possibly improve the fit by weighting the data between 0.01 and 0.03 of your dependent variable a bit more than the remaining points, but unless you have a specific reason to do so (for instance, known lower measurement error in that region), I would accept the fit you have. (You could do repeated measures of your dependent variable at specific, fixed, levels in the 0.0-0.03 range of your dependent variable to estimate the measurement error. You could then do inverse-variance weighting.) If you still have a non-significant term with a weighted-nonlinear least squares fit, I would consider deleting one of your exponential terms, since you apparently only need three to get an acceptable fit.
Doing a weighted nonlinear least squares fit should be relatively straightforward. (I do not have the Curve Fitting Toolbox, so I cannot suggest a specific method. I have the Statistics and Optimization Toolboxes, that are adequate for everything I usually do.)
Since you correctly entered the same information in your comment here as in your Answer, I deleted your Answer.
aalok's "Flag" moved to a "Comment":
"Very nice suggestion"

Sign in to comment.

More Answers (0)

Categories

Find more on Curve Fitting Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!